5
クラスメンバーとしての参照メンバー変数
私の職場では、このスタイルが広く使用されているのがわかります。- #include <iostream> 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; …