刚学C++,请帮我看看下面这个程序,多谢。。。。
# include <iostream.h># include <string.h>
class CPerson
{
protected:
string name;
int age;
public:
CPerson(string n,int a);
CPerson ()
{
cout<<"\n什么也不能做的CPerson构造函数\n";}
void WritePerson()
{
cout<< name<<"年龄为"<<age<<"\n";}
~CPerson()
{
cout<<"\n销毁CPerson对象\n";
}
};
CPerson::CPerson (string n,int a)
{
cout<<"\n在CPerson构造函数中\n";
name=n;
age=a;
WritePerson();
cout<<"离开CPerson构造函数\n";
}
int main()
{
CPerson somebody("Vicent",29);
cout<<"\n没有人了\n\n";
return 0;
}
我用VC++6.0编译时出现了以下错误提示:
:\vc\MSDev98\MyProjects\first18\01.cpp(6) : error C2146: syntax error : missing ';' before identifier 'name'
F:\vc\MSDev98\MyProjects\first18\01.cpp(6) : error C2501: 'string' : missing storage-class or type specifiers
F:\vc\MSDev98\MyProjects\first18\01.cpp(6) : error C2501: 'name' : missing storage-class or type specifiers
F:\vc\MSDev98\MyProjects\first18\01.cpp(9) : error C2629: unexpected 'class CPerson ('
F:\vc\MSDev98\MyProjects\first18\01.cpp(9) : error C2238: unexpected token(s) preceding ';'
F:\vc\MSDev98\MyProjects\first18\01.cpp(21) : error C2065: 'string' : undeclared identifier
F:\vc\MSDev98\MyProjects\first18\01.cpp(21) : error C2146: syntax error : missing ')' before identifier 'n'
F:\vc\MSDev98\MyProjects\first18\01.cpp(21) : error C2350: 'CPerson::CPerson::CPerson' is not a static member
F:\vc\MSDev98\MyProjects\first18\01.cpp(21) : error C2059: syntax error : ')'
F:\vc\MSDev98\MyProjects\first18\01.cpp(22) : error C2143: syntax error : missing ';' before '{'
F:\vc\MSDev98\MyProjects\first18\01.cpp(22) : error C2447: missing function header (old-style formal list?)
F:\vc\MSDev98\MyProjects\first18\01.cpp(31) : error C2661: 'CPerson::CPerson' : no overloaded function takes 2 parameters
执行 cl.exe 时出错.
first18.exe - 1 error(s), 0 warning(s)