Możliwe duplikaty:
[FAQ]Why doesn't a derived template class have access to a base template class' identifiers? Problem with protected fields in base class in c++
cannot access data member in a class templateklasa C++ szablonu i dziedziczenie
następujący kod daje mi błąd kompilacji. Co jest nie tak?
struct Base {
int amount;
};
template<class T> struct D1 : public Base {
};
template<class T>
struct D2 : D1<T> {
void foo() { amount=amount*2; /* I am trying to access base class data member */ };
};
int main() {
D2<int> data;
};
test.cpp: In member function 'void D2<T>::foo()':
test.cpp:11: error: 'amount' was not declared in this scope
Jak to naprawić?
dzięki
Widziałem już to pytanie kilka razy wcześniej, ale nie mogę znaleźć linku. –
Znaleziono jeden, ale jeśli ktoś może znaleźć taki, który ma lepsze pytanie, które byłoby świetne: [Problem z chronionymi polami w klasie bazowej w C++] (http://stackoverflow.com/questions/1813671/problem-w-protected- field-in-base-class-in-c) –
@ Chris: Tutaj jest [duplikat] (http://stackoverflow.com/questions/4210108/cannot-access-data-member-in-a-class-template) , a tutaj jest [długie wyjaśnienie] (http://stackoverflow.com/questions/4643074/why-do-i-have-to-access-template-base-class-members-through-tis-this-pointer). – GManNickG