假设我有以下结构:
class HeavyClass {
public:
static inline HeavyClass const &get() { // note the &
return h_;
}
private:
static HeavyClass h_;
};
HeavyClass HeavyClass::h_();
int main() {
HeavyClass foo = HeavyClass::get(); // critical line
return 0;
}
我的问题是,这真的会在关键线上做我想要的吗?也就是说, foo 会是 h_ 的副本,还是实际上是 h_ 就好像它是通过引用传递的?
非常感谢!