class CPoint
{
int x;
int y;
public:
CPoint(){x=y=0;}
CPoint(int a,int b)
{
x=a;
y=b;
}
void Display()
{
cout <<"宽亏x = " <慎罩神< x << " y = "<< y <<闷漏 endl;
}
};
int main()
{
CPoint p1,p2(2,3);
p1.Display();
p2.Display();
return 0;
}
C++程序:
#include
using namespace std;
class CPoint
{
private:
int x;
int y;
public:
CPoint():x(0), y(0)
{}
CPoint(int x, int y):x(x), 弯友y(y)
{}
void Display()
{
cout<<"("<}
};
int main()
{
CPoint p1 = CPoint(0, 0);
CPoint p2 = CPoint(2, 3);
p1.Display();
p2.Display();
return 0;
}
运行纳巧结果:
(0, 0)
(2, 3)