The question is: What's wrong in the Test() ?Code:class A{ public: A(){} int x; }; class B: public A{ public: B(){} }; void Test(){ A &a = B(); A *p = &B(); } int main(){ Test(); return 1; }
I was told that
(1) at line: A &a = B(); B() is temporary so I need to change it to ' const A &a = B();'
So that I can use a in the future.
(2) A *p = &B(); is correct.