私の職場では、このスタイルが広く使用されているのがわかります。-
#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;
}
このイディオムを説明する名前はありますか?大きな複雑なオブジェクトをコピーすることによるおそらく大きなオーバーヘッドを防ぐためだと思いますか?
これは一般的に良い習慣ですか?このアプローチに落とし穴はありますか?