报错。。。救~
#include<iostream>#include<string>
using namespace std;
class Student;
class Teacher
{
public:
int num;
string name;
char sex;
string zhicheng;
Teacher(int n,string na,char s,string zc):num(n),name(na),sex(s),zhicheng(zc){}
void output(Student &);
};
class Student
{
public:
Student(int n,string na,char s,string zc):num(n),name(na),sex(s),zhiwu(zc){}
int num;
string name;
char sex;
string zhiwu;
Student(Teacher &t)
{
num=t.num;
strcpy(name,t.name);
sex=t.sex;
}
friend void Teacher::output(Student &);
};
void Teacher::output(Student &s)
{
cout<<"Teacher:"<<endl;
cout<<"Num :"<<num<<endl;
cout<<"Name:"<<name<<endl;
cout<<"Post:"<<zhicheng<<endl;
cout<<"Student:"<<endl;
cout<<"Num :"<<s.num<<endl;
cout<<"Name:"<<s.name<<endl;
cout<<"Post:"<<s.zhiwu<<endl;
}
int main()
{
Teacher t(1001,"zhao",'M',"professor");
Student s(1002,"zhoa",'M',"NULL");
t.output(s);
return 0;
}
红色那句报错:
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp1.cpp(28) : error C2664: 'strcpy' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
执行 cl.exe 时出错.
Cpp1.exe - 1 error(s), 0 warning(s)
[[italic] 本帖最后由 zhao9302 于 2007-12-6 16:31 编辑 [/italic]]