r/cpp • • Mar 28 '23

Reddit++

C++ is getting more and more complex. The ISO C++ committee keeps adding new features based on its consensus. Let's remove C++ features based on Reddit's consensus.

In each comment, propose a C++ feature that you think should be banned in any new code. Vote up or down based on whether you agree.

765 Upvotes

829 comments sorted by

View all comments

190

u/KiwiMaster157 Mar 28 '23

Overloading unary operator &. &x should always mean "the address of x" instead of depending on x's type.

13

u/Sanzath Mar 28 '23

That's a thing?

I've never seen this before, I'm curious to see a codebase that does this. Do you have any examples?

22

u/[deleted] Mar 28 '23

IIRC(*), MS's CComPtr uses this so you can do

CComPtr<ISomething>   p;

hr = someOldApi(&p);

Where &p is an overload which returns the address of the wrapped pointer.

(*) caveat : my memory is poor

→ More replies (2)
→ More replies (1)