佐伊买手店:C++的一个问题?

来源:百度文库 编辑:高考问答 时间:2024/05/11 16:41:08
#include<iostream.h>
#include<string.h>
class Cperson
{
private:
char *name[4];
char *ID[12];
char *sex[2];
int age;
public:
void setCperson(char*,char*,char*,int);
void showCperson();
};
void Cperson::setCperson()
{
strcpy(*name)=n;
strcpy(*ID)=I;
strcpy(*sex)=s;
age=a;
}
void Cperson::showCperson()
{
cout<<name<<ID<<sex<<age<<endl;
}
void main()
{
Cperson NewCperson;
NewCperson.setCperson("雷军","200531200211","男",18);
cout<<"The idea is:"<<endl;
NewCperson.showCperson();
}

\Program Files\Microsoft Visual Studio\MyProjects\wuda_1\daohu_1.cpp(15) : error C2511: 'setCperson' : overloaded member function 'void (void)' not found in 'Cperson'
C:\Program Files\Microsoft Visual Studio\MyProjects\wuda_1\daohu_1.cpp(4) : see declaration of 'Cperson'
Error executing cl.exe.
哪里错了啊?

你的setCperson函数的定义不对,你在class中声明的是void (char*,char*,char*,int),带四个参数,但是你定义的那个是个无参的函数,所以说你重写了成员方法,而void(void)这个函数并没有在class中定义

你没有定义,有怎么能传进来参数呢?

你改改,就是这里的问题

你的错误太多了哦

你在类中声名的setCperson函数有四个参数。而你在类外定义该函数时又变成无参类型,当然不行了。