源程序如下:
#include
#include
using namespace std;
class student
{
public:
student(int n,string nam,char s)
{
num=n;
name=nam;
sex=s;
cout<<"construct called"<<endl;
}
~student()
{cout<<"destruct called."<<endl;}
void display()
{
cout<<"num"<<num<<endl;
cout<<"name"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
private:
int num;
string char name;
char sex;
};
int main ()
{
student stud1(10010,"wang",'m');
stud1.display();
student stud2(10011,"zhang",'f');
stud2.display();
return 0;
}
編譯後有個問題:
D:\vc++6.0\sdfdf4\eer.cpp(25) : error C2628: 'string' followed by 'char' is illegal (did you forget a ';'?)
問題出在這:
private:
int num;
string char name;
char sex;
求大神指點
string char name;
這個name是string 還是 char 類型呢。
試一下 改成 string name
或 char* name.