请问:错在那里了?
程序代码:
/* (3)已知个人信息类Cperson的数据成员有姓名、年龄、性别、学号; 从类Cperson派生班级类CClass类,新增加数据成员有年级、班号、人数、班主任。 设计一个主函数实现显示派生类的有关信息。 */ #include <iostream> #include <string.h> using namespace std; //已知个人信息类Cperson的数据成员有姓名、年龄、性别、学号; class cperson { private: char name[30],sex,number; double age; public: void set(char *n,double a,char s,char num) { strcpy(name,n); age=a; sex=s; number=num; } void display() { cout<<"name:"<<name<<",age:"<<age<<",sex:"<<sex<<",number:"<<number<<endl; } }; //从类Cperson派生班级类CClass类,新增加数据成员有年级、班号、人数、班主任。 class cclass:public cperson { private: char grade,class_,people,headmaster[30]; public: void set(char *n,double a,char s,char num,char g,char c,char p,char *h) { cperson::set(*n,a,s,num); strcpy(headmaster,h); grade=g; class_=c; people=p; } void display() { cperson::display(); cout<<"Grade:"<<grade<<",class:"<<class_<<",number of people:"<<people<<",headmaster:"<<headmaster<<endl; } }; void main() { cclass p; p.set("Wang Ming",18,"f","12315","grade 2","class 8","110","Liang Dongqiang"); p.display(); }
错误:
--------------------配置: vc6.0 - CUI Debug, 编译器类型: Microsoft C++ Compiler--------------------
检查文件依赖性...
正在编译 C:\Users\by_stro\Documents\C-Free\Temp\未命名2.cpp...
未命名2.cpp
[Error] C:\Users\by_stro\Documents\C-Free\Temp\未命名2.cpp:36: C2664: 'set' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
[Error] C:\Users\by_stro\Documents\C-Free\Temp\未命名2.cpp:51: C2664: 'set' : cannot convert parameter 3 from 'char [2]' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
构建中止 未命名2: 2 个错误, 0 个警告