Hi, I don't know why my chiled class cannot access parent's variables.
I am using mingw 5.1.3 toolchain.
This works:
but if I change the child to a template class it doesn't:Code:#include <iostream> using namespace std; template< class T > class first { protected: int abc; T def; public: first() { abc = 3; def = 4; } }; class second : first< int > { public: int get_abc() { return abc; } // int get_def() { return def; } }; int main() { second a; // cout << a.get_abc() << endl; cout << a.get_def() << endl; // return 0; }
I get errors that abc and def weren't declared in this scope.Code:#include <iostream> using namespace std; template< class T > class first { protected: int abc; T def; public: first() { abc = 3; def = 4; } }; template< class T > class second : first< T > { public: T get_abc() { return abc; } // T get_def() { return def; } }; int main() { second<int> a; // cout << a.get_abc() << endl; cout << a.get_def() << endl; // return 0; }
Does anyone know a way to overcome this problem( but still keep the hierarchy like ...child2: child1< template > : parent< template > and not move the variables from parent to chiled )?
Thanks.
Domen



LinkBack URL
About LinkBacks




CornedBee