Чем обусловлено обязательное использование указателя this
В данной программе на основе абстрактного базового класса DataStruct был создан производный класс Queue, который по своей сути является очередью. При подмене функций getdata и putdata программа не компилировалась и била ошибку "идентификатор не найден" и "необъявленный идентификатор", до момента, пока я не стал явно использовать указатель this. С чем это может быть связано?
using namespace std;
template<class type1> class DataStruct {
public:
type1 data;
DataStruct<type1>* head;
DataStruct<type1>* tail;
DataStruct<type1>* next;
DataStruct() {
data = NULL; head = tail = next = NULL;
}
virtual type1 getdata() = 0;
virtual void putdata(type1 dt) = 0;
};
template <class type1>
class Queue :public DataStruct<type1> {
public:
type1 getdata();
void putdata(type1 dt);
};
template <class type1>
void Queue<type1>::putdata(type1 dt) {
DataStruct<type1>* temp = new Queue<type1>;
temp->data = dt;
if (this->tail) this->tail->next = temp;
this->tail = temp;
temp->next = NULL;
if (!this->head) this->head = this->tail;
}
template <class type1>
type1 Queue<type1>::getdata() {
DataStruct<type1>* p;
type1 i;
p = this->head;
i = this->head->data;
if (!this->head) {
cout << "Queue is empty!\n";
exit(1);
}
this->head = this->head->next;
delete p;
return i;
}
int main() {
Queue<int> Q;
for (int i = 0; i < 10; i++)
Q.putdata(i);
for (int i = 0; i < 10; i++)
cout << Q.getdata() << ' ';
cout << '\n';
return 0;
} ```