Here are some links about this topic:
http://www.cplusplus.com/forum/beginner/5604/http://www.cplusplus.com/reference/clib ... ring/NULL/http://www2.research.att.com/~bs/bs_faq2.html#nullThe new C++11 standard has a new keyword
nullptr for this (maybe we should decide if we want not only to stick to C++, but also to a specific
standard).
IMHO, these are all good reasons to use 0 (or later nullptr) instead of NULL.
But another topic, about the place of using
const:
- {l Code}: {l Select All Code}
//currently we do this
const int function() const { return 0; }
//according to the standard const works to its left
//and only to the right if there's nothing on its left
//so we should really do this to be standard conform
int const function() const { return 0; }
While this doesn't make any difference on value types, it can make a difference on pointers if one is not careful:
- {l Code}: {l Select All Code}
//(changable pointer) to (constant int)
//const operates on int here
const int* ptr;
//above is the same as same as this
//const still operates on int here
int const* ptr;
//(constant pointer) to (changable int)
//const operates on * here
int* const ptr
//(constant pointer) to (constant int)
int const * const ptr;
Any opinions here? I'm still undecided what I like more. Having const on the left makes reding the code easier, imho. But sticking to the standard has more value as an argument than plain readability, I think.