感觉好麻烦啊,调了半天终于可以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;
}