1

I have this piece of code:

#include <iostream>
using namespace std;

template<class T>
class Base{
protected: T i, j;
}

template<class T>
class Derived: public Base<T>{
public: void set_i_j(T x, T y) { i = x; j = y;}
}
...

If I try this code I get 2 errors, that 'i' and 'j' weren't 'declared in this scope'. I looked for answers and I found that if I write this it works:

this->i = x; this->j = y;

Now the question is why does it work with 'this->'? Or, better put, why doesn't it work without?

Note: This is just a simple example, I was trying to make circular lists derived from simple lists.

Megid
  • 105
  • 12

0 Answers0