一段程序出错,求改正
程序代码:
#include <iostream> #include <string> using namespace std; class Teacher {public: Teacher(string nam,int a,string t) {name=nam; age=a; title=t; } void display() { cout<<"name:"<<name<<endl; cout<<"age:"<<age<<endl; cout<<"title:"<<title<<endl; } protected: string name; int age; string title; }; class Student {public: Student(char nam[],char s,float sco) {strcpy(name1,nam); sex=s; score=sco; } void display1() {cout<<"name:"<<name1<<endl; cout<<"sex:"<<sex<<endl; cout<<"score:"<<score<<endl; } protected: string name1; char sex; float score; }; class Graduate:public Teacher,public Student {public: Graduate(string nam,int a,char s,string t,float sco,float w): Teacher(nam,a,t),Student(nam,s,sco),wage(w){} void show() { cout<<"name:"<<name<<endl; cout<<"age:"<<age<<endl; cout<<"sex:"<<sex<<endl; cout<<"score:"<<score<<endl; cout<<"title:"<<title<<endl; cout<<"wages:"<<wages<<endl; } private: float wage; }; int main() { Graduate grad1("Wang-Li",24,'f',"assistant",89.5,1200); grad1.show(); return 0; }
程序代码:
C:\Users\SAMSUNG\Desktop\.....cpp In constructor 'Student::Student(char*, char, float)': 26 20 C:\Users\SAMSUNG\Desktop\.....cpp [Error] 'strcpy' was not declared in this scope C:\Users\SAMSUNG\Desktop\.....cpp In constructor 'Graduate::Graduate(std::string, int, char, std::string, float, float)': 43 45 C:\Users\SAMSUNG\Desktop\.....cpp [Error] no matching function for call to 'Student::Student(std::string&, char&, float&)' 43 45 C:\Users\SAMSUNG\Desktop\.....cpp [Note] candidates are: 25 3 C:\Users\SAMSUNG\Desktop\.....cpp [Note] Student::Student(char*, char, float) 25 3 C:\Users\SAMSUNG\Desktop\.....cpp [Note] no known conversion for argument 1 from 'std::string {aka std::basic_string<char>}' to 'char*' 23 7 C:\Users\SAMSUNG\Desktop\.....cpp [Note] Student::Student(const Student&) 23 7 C:\Users\SAMSUNG\Desktop\.....cpp [Note] candidate expects 1 argument, 3 provided C:\Users\SAMSUNG\Desktop\.....cpp In member function 'void Graduate::show()': 51 22 C:\Users\SAMSUNG\Desktop\.....cpp [Error] 'wages' was not declared in this scope