#include <vector> #include <iostream> template <class T> class Base { protected: std::vector<T> data_; }; template <class T> class Derived : public Base<T> { public: void clear() { data_.clear(); } }; int main(int argc, char *argv[]) { Derived<int> derived; derived.clear(); return 0; } I cannot compile this program. I get:
main.cpp:22: error: 'data_' was not declared in this scope Please, could you explain why data_ is not visible in the Derived class?
To fix this, you need to specify Base<T>::data_.clear() or this->data_.clear(). As for why this happens, see here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With