S
saneman
In the below non-template example a subclass BOB returns a protected
field from a super class POP:
class POP {
protected:
int blop;
};
class BOB : public POP {
public:
int size () {return blop;}
};
If I declared them as templates I get an error:
template <class A>
class POP {
protected:
int blop;
};
template <typename A, typename B = POP<A> >
class BOB : public B {
public:
int size () {return blop;}
};
error: ‘blop’ was not declared in this scope
It only works if it change the size() function to:
int size () {return B::blop;}
But I can also change it to:
int size () {return A::blop;}
even though I don't make sense, but the compiler does not complain.
When is it necessary to qualify inherited fields when using templates?
field from a super class POP:
class POP {
protected:
int blop;
};
class BOB : public POP {
public:
int size () {return blop;}
};
If I declared them as templates I get an error:
template <class A>
class POP {
protected:
int blop;
};
template <typename A, typename B = POP<A> >
class BOB : public B {
public:
int size () {return blop;}
};
error: ‘blop’ was not declared in this scope
It only works if it change the size() function to:
int size () {return B::blop;}
But I can also change it to:
int size () {return A::blop;}
even though I don't make sense, but the compiler does not complain.
When is it necessary to qualify inherited fields when using templates?