EffectiveC++ Item28 test case

感觉好麻烦啊,调了半天终于可以run了,好吧,贴代码是我的风格:

#include <iostream>
#include <boost/shared_ptr.hpp>
using namespace std;

class Point
{
public:
	Point(){}
	Point(int x, int y):m_X(x),m_Y(y)
	{
	}
	int GetX()const
	{
		return m_X;
	}
	int GetY()const
	{
		return m_Y;
	}
	void setX(int newVal)
	{
		m_X = newVal;
	}
	void setY(int newVal)
	{
		m_Y = newVal;
	}
private:
	int m_X;
	int m_Y;
	
};

struct RectData
{
	RectData(){}
	RectData(Point &a1,Point &a2)
	{
		ulhc = a1;
		lrhc = a2;
	}
	Point ulhc;
	Point lrhc;
};

class Rectangle 
{
public:
	Rectangle(RectData& aData)
	{
		m_pData = boost::shared_ptr<RectData>(new RectData(aData));
	}
	const Point& GetUpperLeft()const
	{
		return m_pData->ulhc;
	}
	const Point& GetLowerRigth()const
	{
		return m_pData->lrhc;
	}

private:
	boost::shared_ptr<RectData> m_pData;
};

class GuiObject
{
public:
	GuiObject(Rectangle &aRect):m_Rect(aRect){}
	Rectangle GetRect()const
	{
		return m_Rect;
	}
private:
	Rectangle m_Rect;
};
const Rectangle BoundingBox(const GuiObject& aObj)
{
	return aObj.GetRect();
}

int main()
{
	Point lp1(1,2),lp2(3,4);
	RectData lRect;
	lRect.lrhc = lp1;
	lRect.ulhc = lp2;
	Rectangle lRectangle(lRect);
	GuiObject *lpGUI = new GuiObject(lRectangle);
	const Point* lpUpperLeft = &(BoundingBox(*lpGUI).GetUpperLeft());
	cout << lpUpperLeft->GetX() << " " << lpUpperLeft->GetY() << endl;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值