首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

cout与种定义

2013-04-02 
cout与类定义自己写着好玩,后来发现个问题。3个类,一个human,一个student ,一个teacher .后两个是第一个子

cout与类定义
   自己写着好玩,后来发现个问题。3个类,一个human,一个student ,一个teacher .后两个是第一个子类。
    然后我在human protect定义了个sta static int cout;就出现错误
D:\C++lean\student.cpp|10|error: invalid operands of types 'int' and 'const char [27]' to binary 'operator<<'|;
去掉定义 就没事。。报错行:cout<<"student specialty ready go"<<endl;
代码


human.h
#ifndef HUMAN_H
#define HUMAN_H


class human
{
    public:
        human();
        virtual ~human();
    protected:
    int height;//身高
    int weight;//体重
    char *hope;//理想
    char *name;//名字
  //  static int cout;//加入这个定义则会报错,不加没事。
  //  human *pnext;
  //  human *pfirst;
};

#endif // HUMAN_H

human.cpp
#include "human.h"
#include <iostream>
#include<string.h>
using namespace std;

human::human()
{
    hope=new char[20];
   strcpy(hope,"no geven hope\0");
   cout<<"human hope ready go"<<endl;
   name=new char[20];
   strcpy(name,"no geven name\0");
   cout<<"human name ready go"<<endl;
}

human::~human()
{
    delete []hope;
    delete []name;
    cout<<"human delete completion"<<endl;
    //dtor
}

student.h
#ifndef STUDENT_H
#define STUDENT_H

#include "human.h"

class student:public human
{
    public:
        student();
        virtual ~student();
    protected:
     int sorce;//分数
     char *specialty;//特长
    private:
};

#endif // STUDENT_H
student.cpp
#include "student.h"
#include <iostream>
#include<string.h>
using namespace std;

student::student()
{
     specialty=new char[20];
   strcpy(specialty,"no geven specialty\0");
   cout<<"student specialty ready go"<<endl;
}

student::~student()
{
    delete []specialty;
    cout<<"stduent specialty completion"<<endl;

}

main.cpp
#include <iostream>
#include<string.h>
#include "human.h"
#include "student.h"
#include "teacher.h"
using namespace std;

int main()
{
    human a;
    cout<<endl;
    student b;
    cout<<endl;
    teacher c;
}





[解决办法]


cout这个变量名和 库函数 cout 冲突了,换个名 ,比如nCount

热点排行