Why can't a C++ compiler recognize that g()
and b
are inherited members of Superclass
as seen in this code:
template<typename T> struct Superclass {
protected:
int b;
void g() {}
};
template<typename T> struct Subclass : public Superclass<T> {
void f() {
g(); // compiler error: uncategorized
b = 3; // compiler error: unrecognized
}
};
If I simplify Subclass
and just inherit from Subclass<int>
then it compiles. It also compiles when fully qualifying g()
as Superclass<T>::g()
and Superclass<T>::b
. I'm using LLVM GCC 4.2.
Note: If I make g()
and b
public in the superclass it still fails with same error.
Superclass<T>::b
andSuperclass<T>::g()
, 2) Use the prefixesthis->a
andthis->g()
, 3) Add statementsusing Superclass<T>::a
andusing Superclass<T>::g
, 4) Use a global compiler switch that enables the permissive mode. The pros & cons of these solutions are described in stackoverflow.com/questions/50321788/… – George Robinson