1

This works fine:

    class A{
    protected:
    int i;
    };

    class B:public A{
    public:
    void f(){
        i=5; //fine
      }
    };

However if I try to do the same with static polymorphism, it fails:

template <class Derived, typename T, int N>
class Vector{

protected:

std::vector<T> v;

Then:

  template <typename T, int N>
  class Vector234:public Vector<Vector234<T, N>,T,N>{

    void test(){
        T t=v[0]; // v is undeclared identifier
    }

Why is this?

johnbakers
  • 24,158
  • 24
  • 130
  • 258
  • This is addressed in questions http://stackoverflow.com/questions/1624564/access-protected-member-of-a-class-in-a-derived-class and http://stackoverflow.com/questions/11405/gcc-problem-using-a-member-of-a-base-class-that-depends-on-a-template-argument – sfstewman Jun 05 '13 at 06:34

1 Answers1

0

Because it's a dependent name, that is, it depends on the template parameter T. You need to explicitly specify either this->v[0] or Vector<Vector234<T, N>,T,N>::v[0].

Yuushi
  • 25,132
  • 7
  • 63
  • 81