const reference to temporary oddity

前端 未结 3 1426
情深已故
情深已故 2021-01-02 11:14

We all know that things like this are valid in c++:

const T &x = T();

while:

T &x = T();

is not.<

3条回答
  •  悲&欢浪女
    2021-01-02 11:25

    You just got lucky. Changing B::b to this:

    void b() {
        int i = rand();
        int j = rand();
        cout << _a << endl;
    }
    

    prints out random numbers.

提交回复
热议问题