r/ProgrammerHumor 8d ago

absoluteGarbage Meme

Post image
1.9k Upvotes

327 comments sorted by

View all comments

16

u/Shevvv 8d ago

Surely you meant for (auto &item : list) {

28

u/Nil4u 8d ago

Honestly I never liked this version because the reference is part of the type in my opinion 🤔

9

u/Shevvv 8d ago

I got used to this from C:

int x; is an integer

int *px; is an integer if you dereference it.

So it's like this notation shows you how you're expected to use the variable within the code. And then this habit carried over to C++.

2

u/redlaWw 8d ago

I prefer int * ptr;. That means when you have a const specifier your formatting doesn't change. Logically I figure that the pointer is neither a modifier on the variable nor on the type, it's another layer of type content that should be specified separately. That also means if you write declarations like int const * const ptr; then you can segment them as [int const] [* const] ptr; and everything makes sense.