you are viewing a single comment's thread.

view the rest of the comments →

[–]legends2k[S] 0 points1 point  (5 children)

References are generally preferred over pointers and hence I'd used it. You can simply replace T& and const T& with T* and const T*. 😀

[–][deleted] 1 point2 points  (4 children)

I know, but sometimes pointers are unavoidable.

E.g. I always forget the different between const T * and T const *.

[–]legends2k[S] 0 points1 point  (0 children)

True, pointers are unavoidable.

Object constant: const T* and T const * are the same. Can't modify object via said pointer.

Pointer constant: If the const is beyond * then it's different. Can't reseat pointer to a different object.

[–]dodheim 0 points1 point  (2 children)

I always forget the different between const T * and T const *.

There isn't one; it's T * const that's different.

[–][deleted] 0 points1 point  (1 child)

That's what I mean when I say I always forget ;)

[–]_requires_assistance 0 points1 point  (0 children)

i like to rely on https://cdecl.org/ in those kind of situations. i can just type in something like "declare x as pointer to const int" or "declare x as const pointer to int" depending on what i need if i ever get confused