c++ - Using and re-defining typedef from base class -


is legal name refer base class member in 1 part of class definition , derived class member in another? code demonstrates it:

struct base {   typedef int t; };   struct derived : base {   t m1; //type int   typedef t *t;   t m2; //type int* }; 

i haven't been able find ruling against in standard. code legal?

yes, legal. make no comment on whether or not it's advisable.

first, need able redeclare different entity same name in derived class; allowed 3.3.10/1 (with emphasis):

a name can hidden explicit declaration of same name in nested declarative region or derived class.

then need t refer base::t in declaration of derived::t; i.e. derived::t must not in scope @ point. scope defined 3.3.3/1:

its potential scope begins @ point of declaration , ends @ end of block.

and point of declaration defined 3.3.2/1:

the point of declaration name after complete declarator

meaning that, before , during declarator, derived::t not in scope , t refers base::t.


Comments