Olası çoğaltmaları:
[SSS]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 templateC++ şablon sınıfı ve miras
kodunu takiben bana derleme hata veriyor. Yanlış olan ne?
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
Bunu nasıl düzeltebilirim?
sayesinde
sorun burada isimleri şablon taban sınıflardan miras şablon sınıflarında aranır nasıl bir ilgisi vardır
Bu soruyu birkaç kez daha önce görmüştüm ama bir bağlantı bulamıyorum. –
Birisi, birisi daha iyi bir soruyla bir tane bulabilirse iyi bir fikir bulmuş olsa da: [C++ 'da temel sınıftaki korunan alanlarla ilgili sorun) (http://stackoverflow.com/questions/1813671/problem-with-protected- alanları-in-base-class-in-c) –
@ Chris: İşte bir [çift] (http://stackoverflow.com/questions/4210108/cannot-access-data-member-in-a-class-template) ve işte bu [uzun bir açıklama] (http://stackoverflow.com/questions/4643074/why-do-i-have-to-access-template-base-class-members-through-the-this-pointer). – GManNickG