error C2440: '=' : cannot convert from 'class std::basic_string是什么意思?
代码如下:
#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
student(int n,string nam,char s)
{
num =n;
name=nam;
sex =s;
cout<<"Constructor called."<<endl;
}
~Student()
{
cout<<"Destructor called."<<endl;
}
void display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
private:
int num;
char name[10];
char sex;
};
int main()
{
Student stud1(10010,"Wang_li",'f');
stud1.display();
Student stud2(10011,"Zhang_fun",'m');
stud2.display();
system("pause");
return 0;
}
编译提示:
D:\vc\project\console\8_1\8_1.cpp(14) : warning C4183: 'student': member function definition looks like a ctor, but name does not match enclosing class
D:\vc\project\console\8_1\8_1.cpp(11) : error C2440: '=' : cannot convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char [10]'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
D:\vc\project\console\8_1\8_1.cpp(36) : error C2661: 'Student::Student' : no overloaded function takes 3 parameters
D:\vc\project\console\8_1\8_1.cpp(39) : error C2661: 'Student::Student' : no overloaded function takes 3 parameters
是什么意思?怎么解决?