// @topic T00750 Initializer lists and const qualifiers // @brief 10/18/2012 -- reference as class member, using *this class CPoint { // member variables int m_x; int m_y; public: // constructors CPoint() // default ctr : m_x( 0 ), m_y( 0 ) { } CPoint( CPoint& other ) // copy ctr : m_x( other.m_x ), m_y( other.m_y ) { //m_x = other.m_x; //m_y = other.m_y; } CPoint( int xx, int yy ) // specific ctr : m_x( xx ), m_y( yy ) { //m_x = xx; //m_y = yy; } // operations CPoint& get_reference() { return *this; } CPoint* get_pointer() { return this; } void adjust( int xx, int yy ) { m_x += xx; m_y += yy; } };//class CPoint class CView { CPoint& m_pt_one; CPoint& m_pt_two; public: CView( CPoint& pt1, CPoint& pt2 ) // no pt ctr is invoked : m_pt_one( pt1 ), // member initialization syntax m_pt_two( pt2 ) { //m_pt_one = pt1; // cannot initialize member references in the constr body //m_pt_one = pt2; } };//class CView int main() { CPoint pt( 5, 7 ); pt.adjust( 100, 200 ); CView view( pt, pt ); // examples of standalone reference and pointer: CPoint& refpt = pt.get_reference(); CPoint* ptr = pt.get_pointer(); return 0; }//main