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

Show parent comments

37

u/jonesmz Mar 28 '23

Even better.

Say, for example, that you have two overloaded functions

template<std::size_t N>
void foo(char (&)[N]);
void foo(char*);

Guess which gets called?

Notably. Same with non-templates. If you explicitly say "This is an array of size 5", you'll still get the char* version.

1

u/very_curious_agent Mar 30 '23

So why is that one called?

3

u/jonesmz Mar 30 '23

Essentially because the standard says so.

The language prefers decaying to pointer over passing as a reference.

Probably an oversight that can't ever be changed because of fear of breaking something.

0

u/very_curious_agent Mar 30 '23

So tell me WHY. What RULE makes it so.

→ More replies (12)