我有以下c ++代码,我在其中遇到构建错误。我无法找到任何一个帮助的错误。这是代码
#include<stdlib.h>
#include <iostream.h>
using namespace std;
class PropertyPortal;
class PropertyType;
class Commercial;
class Residential;
void main()
class PropertyPortal
{
private:
int NoOfUsers;
int UAN;
char* Name;
public:
void setNoOfUsers(int no);
void setUAN(int u);
void setName(int n);
int getNoOfUsers();
int getUAN();
char getName();
int getPropertyInfo();
//constructors of the class
PropertyPortal();
PropertyPortal(int, int, char);
//destructor of the class
~PropertyPortal ();
void setNoOfUsers(int no)
{
NoOfUsers>=1;
}
void setUAN (int u);
{
NoOfUsers>=0;
UAN>=1;
Name=Null;
}
PropertyPortal (int no, int u, char* n)
{
NoOfUsers>=no;
UAN=u
Name=VU-Real-Estate;
}
PropertyPortal (int no, int u, char* n)
{
NoOfUsers>=no;
UAN=u
Name=n;
}
void setNoOfUsers(int no)
void setUAN(int u)
void setName(char n)
int getNoOfUsers()
int getUAN()
char getName()
int getPropertyInfo();
class PropertyType
{
private:
char* City
public:
void setCity(char c);
char getCity(char c);
void getPropertyType();
PropertyType();
PropertyType(char);
~PropertyType();
PropertyType();
{
City=Null
}
PropertyType(char* cCity)
{
City=cCity
}
};
class Commercial:PropertyType
{
private:
int PropertyValue
public:
void setPropertyValue();
int getPropertyValue();
void getPlots();
Commercial();
Commercial(char);
~Commercial();
};
class Residential:PropertyType
private:
int PropertyValue;
public:
void setPropertyValue();
int getPropertyValue();
int getPropertyCategory();
};
void main ()
{
cout<<"This is just a prototype of all classes";
cout<<endl;
system("PAUSE");
}
我在第2,32:2,10,103
行上遇到错误请帮我查一下有什么不对,以及代码是什么。
更新
答案 0 :(得分:2)
许多错误来自于在类中包含函数声明和定义。做任何一件事
class Foo
{
public:
int func();
};
int Foo::func() { return 5; }
或
class Foo
{
public:
int func() { return 5; }
};
但不是
class Foo
{
public:
int func();
// ...
int func() { return 5; }
};
我还看到你打算有两个构造函数,一个具有默认值,另一个从创建者中获取值。但是你这样做了:
PropertyPortal (int no, int u, char* n)
{
NoOfUsers>=no;
UAN=u
Name=VU-Real-Estate;
}
PropertyPortal (int no, int u, char* n)
{
NoOfUsers>=no;
UAN=u
Name=n;
}
我怀疑你的意思是
PropertyPortal ()
{
NoOfUsers=1;
UAN=1;
Name="VU-Real-Estate";
}
PropertyPortal (int no, int u, char* n)
{
NoOfUsers=no;
UAN=u
Name=strdup(n); // Remember to free() this later.
}
事实上,你最好一起废弃char*
,并使用std::string
,也许可以阅读initializer lists。