有什么区别
你能给我一些例子吗?
在我的工作地点,我看到这种风格被广泛使用: -
#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;
}
Run Code Online (Sandbox Code Playgroud)
有没有名称来形容这个成语?我假设它是为了防止复制大型复杂对象的可能大量开销?
这通常是好的做法吗?这种方法有什么缺陷吗?