bb wrote:
Please could someone throw some light on why the following definitions
are not the same?
class A {
const int& a, b; // b does not get defined as a
ref. but a plain int
const int& x; const int& y; // obviously, both are refs.
...
};
It really has nothing to do with comma operator, you know.
The rules of declarations are such that '*' and '&' are part of the
individual object declaration, whereas the type (the 'const int' part
in your example) is common for all objects. IOW, the same thing would
happen if you declared 'a' as a pointer to const int:
const int* a, b; // 'a' is a pointer, 'b' is not.
To avoid mistakes like that, declare each object in its own separate
statement, or use typedefs:
typedef const int *pointerToConstInt;
pointerToConstInt a, b; // both 'a' and 'b' are pointers now
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask