1

Possible Duplicate:
GCC problem : using a member of a base class that depends on a template argument

template <typename AType, typename OuterClass>
class A{
public:
    A (AType a, OuterClass & b) : a(a), b(b) { }
    AType a;
    const OuterClass & b;
};

template <typename T>
class B {
public:
    class C : public A<int, B> {
        C(const B & b) : A<int, B>(0, b) {} 
        int getA() { return a; }
    };
};

This code is a little long, but it's the minimal example I could find to reproduce my problem. Class C should inherit field "a" from its superclass A, and visual c++ compiles it without errors. But for some reason under gcc, in function getA I get "error: ‘a’ was not declared in this scope". What's wrong with this code and how can I make it more portable?

Community
  • 1
  • 1
  • Yes, it seems that my problem is the same as the one in the link you provided. And the solution given there (using this->a or A::a instead of simply a) solves my problem. Thanks. – user1284240 Mar 21 '12 at 19:28
  • This happens because of the two-phase name lookup (which not all compilers use by default). There are 4 solutions to this problem: **1)** Use the prefix `A::a`, **2)** Use the prefix `this->a`, **3)** Add a statement `using A::a`, **4)** Use a global compiler switch that enables the permissive mode. The pros & cons of these solutions are described in https://stackoverflow.com/questions/50321788/a-better-way-to-avoid-public-member-invisibility-and-source-code-bloat-repetitio – George Robinson May 14 '18 at 13:41

0 Answers0