Ссылочные переменные-члены как члены класса

В моем месте работы я вижу, что этот стиль широко используется: -

#include 

using namespace std;

class A
{
public:
   A(int& thing) : m_thing(thing) {}
   void printit() { cout < m_thing < endl; }

protected:
   const int& m_thing; //usually would be more complex object
};


int main(int argc, char* argv[])
{
   int myint = 5;
   A myA(myint);
   myA.printit();
   return 0;
}

Ответы на вопрос(5)

Ваш ответ на вопрос