BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #38728同步于 2010/4/29
CPP机器人发帖

和类有关的问题

w09210284
2010/4/29镜像同步0 回复
#include <iostream> using namespace std; class student; class teacher { private: int id; char* name; public: void get(); void assigngrade(student &a); };//注意 class student { private: static int cout; int number; char* name; char* subject; float grade; public: student(int num,char * nam,char*sub,float grad);//注意 函数定义在类里面的话便不能 用头文件的cout ~student(); void get(); void show(); friend class teacher; }; student::student(int num,char * nam,char*sub,float grad) { number=num; name =new char[sizeof(nam)]; strcpy(name,nam); subject=new char[sizeof(sub)]; strcpy(subject,sub ); grade=grad; cout++; } student::~student() { cout<<"学号:"; delete []name; delete []subject; cout--; } void student::get() { cout<<"请输入学号 名字 科目 成绩"<<endl; int n=10; int m=10; name=new char[n]; subject=new char[m]; cin>>number>>name>>subject>>grade; n=strlen(name)+1; m=strlen(subject)+1; } void teacher::get() { int i; cin>>i; id=i; int a=10; name=new char[a]; cin>>name; a=strlen(name)+1; } void teacher::assigngrade(student& a) { float b; cin>>b; a.grade=b;//注意当写函数原型时打分号 当直接定义函数时 不要打 } void student::show() { cout<<number<<'\t'<<name<<'\t'<<subject<<'\t'<<grade<<endl; } int student::cout=0; int main() { int n; cout<<"请输入要输入学生的数目"<<endl; cin>>n; return 0; } 为什么编辑出现这种错误 哪位大牛帮帮我这个小菜啊 Compiling... 2.cpp E:\编程\自己的程序\郁闷的类\2.cpp(43) : error C2297: '<<' : illegal, right operand has type 'char [7]' E:\编程\自己的程序\郁闷的类\2.cpp(50) : error C2297: '<<' : illegal, right operand has type 'char [26]' E:\编程\自己的程序\郁闷的类\2.cpp(78) : error C2297: '<<' : illegal, right operand has type 'char *' Error executing cl.exe. 2.obj - 3 error(s), 0 warning(s)
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。