I found a situation that allowed me to think about this syntax. Consider a smart pointer to a Base class that must contain a pointer to a derived class, and you want to access some non-virtual things of the derived class after building. In this case, something like this is legal and may not be so bad:
Derived & d = * new Derived(); d.d_method( ..whatever.. ); d.d_member = ..whatever..; ... std::unique_ptr<Base> p( &d );
Finally, I still preferred small arrows for weird ampersands:
Derived d = new Derived(); d->d_method( ..whatever.. ); d->d_member = ..whatever..; ... std::unique_ptr<Base> p( d );
But I think that in this case itβs just a matter of taste, especially if you get access to a consistent number of methods.
Other things that cause leaks or delete &d; just bad, bad, bad.
Dariop
source share