B
Bo Yang
I know the below code is wrong:
Object & test(){ return Object() ;}
Object & v = test() ;
the Object is just a temporary variable,
so you the variable may be reference to
nothing.
And I try to this:
Object & test () { return * new Object(); }
Object & v = test () ;
But how can I destroy the Object's memery?
But, how to return reference safely?
Is there any principle to return by reference?
Object & test(){ return Object() ;}
Object & v = test() ;
the Object is just a temporary variable,
so you the variable may be reference to
nothing.
And I try to this:
Object & test () { return * new Object(); }
Object & v = test () ;
But how can I destroy the Object's memery?
But, how to return reference safely?
Is there any principle to return by reference?