What are some C++ related idioms, misconceptions, and gotchas that you\'ve learnt from experience?
An example:
class A
{
public:
char s[1024];
cha
Sometimes, headers are polluted with not behaving macro names like
#define max(a, b) (a > b ? a : b)
Which will render code invalid that uses a max function or function object called that way. An infamous example is windows.h
which does exactly that. One way around it is putting parentheses around the call, which stops it from using the macro and makes it use the real max function:
void myfunction() {
....
(max)(c, d);
}
Now, the max is in parentheses and it is not counted as a call to the macro anymore!