哪里错了,大家看一下吧谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/16 18:01:03
#include "iostream.h"
class Sample()
{
private:
int x,y;
public:
Sample()
{x=y=0;}
Sample(int a,int b)
{x=a;y=b;}
~Sample()
{
if(x==y) cout<<"x=y"<<endl;
else cout<<"x!=y"<<endl;
}
void disp()
{ cout<<"x="<<x<<" y="<<y<<endl;}
};
void main()
{
Sample s1(2,3);
}

就这么简单一个类,却找不到错误,编绎不断报错,是怎么回事?

ompiling...
205.cpp
G:\C++程序设计语言题典\5.16\205.cpp(4) : error C2143: syntax error : missing ';' before 'private'
G:\C++程序设计语言题典\5.16\205.cpp(6) : error C2143: syntax error : missing ';' before 'public'
G:\C++程序设计语言题典\5.16\205.cpp(8) : error C2143: syntax error : missing ';' before '{'
G:\C++程序设计语言题典\5.16\205.cpp(8) : error C2065: &

多一个()
#include "iostream.h"
class Sample
{
private:
int x,y;
public:
Sample()
{x=y=0;}
Sample(int a,int b)
{x=a;y=b;}
~Sample()
{
if(x==y) cout<<"x=y"<<endl;
else cout<<"x!=y"<<endl;
}
void disp()
{ cout<<"x="<<x<<" y="<<y<<endl;}
};
void main()
{
Sample s1(2,3);
}