C++在一个类中引用另一个类的对象

#include<iostream>
using namespace std;
class point
{
private:
	int x;
	int y;
public:
	int getx()//如何引用私有类的成员
	{
		return x;
	}
	void setx(int xx)
	{
		 x = xx;
	}
	int gety()//如何引用私有类的成员
	{
		return y;
	}
	void sety(int yy)
	{
		y = yy;
	}
	void input()
	{
		cin >> x >> y;
	}
	void output()
	{
		cout << "(" << x << "," << y << ")" << endl;
	}
};
class line
{
private:
	point p1, p2;
public:
	void input()
	{
		p1.input();
		p2.input();
	}
	void output()
	{
		p1.output();
		p2.output();
	}
};
int main()
{
   line a;
	a.input();
	a.output();
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43312665/article/details/88202001