P
Phlip
Goran said:Is it possible to overload a member variable?
Yes; they are just two different variables. The working model here is that
each class gives its data members scope and a storage slot. Deriving a
class opens a new scope and a new storage region. Activity in that scope
will look-up identifiers within its scope first, so the situation is
exactly the same as this:
int x = 42;
{ int x = 43; }
assert( 42 == x );
Nothing overloaded the first x. This is among the reasons to use accessors
(virtual int get_x() around raw data; you can override them.
Otherwise, such an approach is not usual because you should not confuse your
maintainers (including yourself), and you should not duplicate your
program's design elements. If your two class's itsValue are the same value,
they should also be the same variable. This improves design.
New question; what do these do?
int x = 42;
{ int &x = x; ++x; }
assert( ?? == x );
{ int &x(x); ++x; }
assert( ?? == x );
{ int x = x;
assert( ?? == x ); }
{ int x(x);
assert( ?? == x ); }