I have a Derived template class that inherited from a Base template class. The Base class has a pure virtual method and protected attribute which I am using in the implemented version Derived class. However whenever I use the inherited attribute in the implement version of the pure virtual function I get ‘identifier not found’ and ‘undeclared identifier’ error.
I am using visual studio 2022 editor
Here is my code:
#include <iostream>
template <class T>
class Base {
public:
T a{};
virtual void someVfunc1() = 0;
protected:
T b{};
T c{};
};
template <class T>
class DerivedClass: public Base<T> {
public:
void saysome() {
b = 23;
std::cout << "some = " << b << std::endl;
}
void someVfunc1() {
b = 44;
std::cout << "some = " << b << std::endl;
}
DerivedClass() {};
};
int main() {
DerivedClass<int> d{};
d.saysome();
d.someVfunc1();
return 0;
}
in both method call I keep getting C2065: 'b': undeclared identifier
and error C3861: 'b': identifier not found
However if I remove the templating for the classes, It runs perfectly.
How can I get it to run even with the templating format
Adeoye Adegbite is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.