When inheriting from a template class, I need to prefix all base class members I access in the derived class with this
:
template<typename T>
struct X{
int foo;
void bar();
};
template<typename T>
struct Y : public X<T> {
void blub(){
foo++; // Does not work
this->foo++; // Fine
bar(); // Does not work
this->bar(); // Fine
}
}
As I was hinted, the reason why you must prefix the members with this
has already been answered HERE. So my remaining question is: Is there a way to avoid all the this
es? For example, I have a method in the derived class that uses a lot of base class members. The code looks totally cluttered with all the this->
in it. Is there a way to omit these?