求助:大家帮我看看这个程序错在哪了,我按着书上说的写得阿
#include <iostream.h>class DataClass
{
private:
int PrivateDataMember;
public:
DataClass(int Value);
int PublicDataMember;
int PublicMethod(void);
}
DataClass::DataClass(int Value)
{
PrivateDataMember=Value;
}
int DataClass::PublicMethod(void)
{
return PrivateDataMember;
}
void main()
{
DataClass DataObject(1);
DataObject.PublicDataMember=2;
cout<<"DataObject.PublicDataMember="<<
DataObject.PublicDataMember<<"n";
cout<<"DataObject.PrivateDataMember="<<
DataObject.PublicDataMember<<"n";
}
运行后出现:E:\VC++\classes\classes.cpp(12) : error C2533: 'DataClass::DataClass' : constructors not allowed a return type
E:\VC++\classes\classes.cpp(21) : error C2264: 'DataClass::DataClass' : error in function definition or declaration; function not called
我在网上看到有人说:在类定义或者申明时,结束的地方忘了加个';
我在public:
DataClass(int Value); 加了一个'还是不行啊,
int PublicDataMember;
int PublicMethod(void)
请教大家怎么办呢