If I have a class that contains a number of typedef
'd variables, like so:
class X {
typedef token TokenType;
bool doStuff()
{
TokenType data;
fillData(&data);
return true;
}
};
Is there any way to override the typedef
for TokenType
in a derived class?
N.B. This is NOT a good place to use templates (This is already a templated class and any changes are likely to result in [EDIT: infinite] recursive definitions [class X < class Y = class X < class Y . . .> >
etc.].)
What you can do is shadow, but not override. That is: you can define a derived class Y with its own typedefs for TokenType, but that will only come into play if somebody references Y::TokenType directly or via an object statically typed as Y. Any code that references X::TokenType statically will do so even for objects of type Y.
Typedefs are resolved at compile time – making them overridable would be meaningless, since overriding is a feature of runtime polymorphism.
Simply redeclaring the typedef will work – though I'm not sure why you think templates would be a bad idea here – recursive templates are actually feasible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With