c++ 程序报错求解释解答跟解决方法 谢谢

#include<string>
#include <iostream>
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 dispaly()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl<<endl;
}
private:
int num;
char name[10];
char sex;
};
int main()
{
Student stud1(10010,"wang_li",'f');
stud1.dispaly();
Student stud2(10011,"zhang_fan",'m');
stud2.dispaly();
return 0;
}
C:\Documents and Settings\Administrator\4248.cpp(10) : 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
Error executing cl.exe.
4248.obj - 1 error(s), 0 warning(s)

int sum(int a;int b;int c)
{
 int sum=a+b+c;
 return 0;
}
  1)函数中sum又被定义为变量了,改个名字吧 ã€‚二义性了。
 2)分隔符一般用逗号,而不是分号
按照你main函数中的定义,你的sum可以定义为:
int sum(int a,int b,int c)
{
   return a+b+c;
}追问

sum 在哪?

温馨提示:答案为网友推荐,仅供参考
相似回答