C++编程问题,急

来源:百度知道 编辑:UC知道 时间:2024/06/14 04:07:42
这段程序有几个问题,哪位高人指点一下
#include<iostream.h>
class Sample
{
public:
Sample(int a=0,b=1);
disp();
private:
int x,y;
};
Sample::Sample(int a=0,int b=1)
{
x=a;y=b;
}
void Sample::disp()
{
cout<<"x="<<x<<",y="<<y<<endl;
}

#include<iostream>
using namespace std;
class Sample
{
public:
Sample(int a=0,int b=1);
void disp();
private:
int x,y;
};
Sample::Sample(int a,int b)
{
x=a;y=b;
}
void Sample::disp()
{
cout<<"x="<<x<<",y="<<y<<endl;
}
int main()
{Sample g;
g.disp();
return 0;
}
这程序是用默认参数的构造函数,我不知道你的主函数是不是这,如果不是,你在补充一下

#include<iostream>
using namespace std;
class Sample
{
public:
Sample(int,int);
void disp();
private:
int x,y;
};
Sample::Sample(int a=0,int b=1)
{
x=a;
y=b;
}
void Sample::disp()
{
cout<<"x="<<x<<",y="<<y<<endl;
}

void main(void)
{
Sample a;
a.disp();
}

#include<iostream.h>
class Sample
{
public: