0

I am struggling with a very simple template design:

template <typename T>
class A {
public:
    int i=4;
};

template <typename T>
class B : public  A<T> {
public:
    int f() {return i;}
};

The compiler says that i is not declared in the scope of B. I can solve it by prefixing with A:

int f() {return A<T>::i;}

But, as this is an extract of a more general design, I want to understand the problem: B<T> has A<T> as a father so i should be accessible without prefixing?

I think it must be a trivial problem but I can't see the solution.

Javaddict
  • 483
  • 1
  • 4
  • 15

0 Answers0