0

I have stuck with the following code in some project (it is simplification).

template <class X >
class A {
  public:
    int a;
};

class Y;
class B : public A<Y> {
  void foo() {a = 0;}
};

template < class D >
class C : public A<D> {
  void foo() {a = 0;}
};

The compiler fails with:

test.cpp:14:14: error: ‘a’ was not declared in this scope

Why in the C::foo the compiler fails to recognize A::a and in B::foo does not? Thanks.

Alexander
  • 713
  • 1
  • 7
  • 20

1 Answers1

0

a is a dependent base class member in B, you need to access it with this->a.

Quentin
  • 62,093
  • 7
  • 131
  • 191