高手在哪里啊 ~
#include <iostream >
#include <iomanip >
using namespace std;
class Person
{
int IdPerson;
char Name;
char Sex;
char Birthday;
char HomeAddress;
public:
Person(int ID=0,char name=0,char sex=0,char birth=0,char address=0)
{
IdPerson=ID;
Name=name;
Sex=sex;
Birthday=birth;
HomeAddress=address;
}
Person(const Person &p);
void Insert();
void Display();
};
Person::Person(const Person &p)
{
IdPerson=p.IdPerson;
Name=p.Name;
Sex=p.Sex;
Birthday=p.Birthday;
HomeAddress=p.HomeAddress;
}
void Person::Insert()
{
int I;
char man,woman;
cout < <"Please input an ID:";
cin > >IdPerson;
cout < <"Please input name:";
cin > >Name;
cout < <"Please input the sex(0 for man,and 1 for woman):";
cin > >I;
if(I=0) Sex=man;else Sex=woman;
cout < <"Please input the" < <Sex < <" 's birthday:";
cin > >Birthday;
cout < <"Please input the" < <Sex < <" 's homeaddress:";
cin > >HomeAddress;
}
void Person::Display()
{
cout < <"*********************************************************" < <endl;
cout < <"*";
cout < <setw(15) < <"Name:" < <Name < <endl;
cout < <"*";
cout < <setw(15) < <"Sex:" < <Sex < <endl;
cout < <"*";
cout < <setw(15) < <"Birthday" < <Birthday < <endl;
cout < <"*";
cout < <setw(15) < <"IdPerson" < <IdPerson < <endl;
cout < <"*";
cout < <setw(15) < <"HomeAddress" < <HomeAddress < <endl;
cout < <"*********************************************************";
}
void Insert2(Person &p)
{
p.Insert();
}
void Display2(Person &p)
{
p.Display();
}
void main()
{
Person A(0,0,0,0,0);
A.Insert2();
A.Display2();
}
提示错误:
--------------------Configuration: 4-6 - Win32 Debug--------------------
Compiling...
4-6.CPP
G:\我的文档\C++\4-6.CPP(84) : error C2039: 'Insert2 ' : is not a member of 'Person '
G:\我的文档\C++\4-6.CPP(6) : see declaration of 'Person '
G:\我的文档\C++\4-6.CPP(85) : error C2039: 'Display2 ' : is not a member of 'Person '
G:\我的文档\C++\4-6.CPP(6) : see declaration of 'Person '
执行 cl.exe 时出错.
4-6.exe - 1 error(s), 0 warning(s)
这是什么意思啊 ?
救救我啊~
[解决办法]
这哪要高手啊?很明显的错误啊?
A.Insert2();
A.Display2();
Insert2/Display2又不是对象的成员函数,为什么能这么调用?
很显然应该是Insert2(A);Display2(A);
基础语法还是要好好学习的