I have a templated class that I inherit from, and access through the derived class the base class members. I can't access them without using "this" and I find a descent reason why.
If I understand correctly, when I use a template, a copy of the templated code is being made with a specialization, and only then it compiles. Meaning if I write vector<int>
the compiler makes a copy of vector and replaces all the "T" with "int".
If that is the case, I don't see why there should be any difference between templates and non-templated code.
template <typename T>
class b
{
protected:
int myMember;
};
template<typename T>
class e : public b<T>
{
public:
void dosomething()
{
this->myMember = 2; // Everything is perfect
myMember = 2; // Doesn't compile in GCC, can't find the member
}
};
int main()
{
e<int> mye;
mye.dosomething();
}