just stumbled upon something that I canβt explain. The following code does not compile
template<int a> class sub{ protected: int _attr; }; template<int b> class super : public sub<b>{ public: void foo(){ _attr = 3; } }; int main(){ super<4> obj; obj.foo(); }
whereas when changing _attr = 3; before this->attr = 3; the problem does not arise.
Why? Are there any cases where you should use this?
I used g++ test.cpp -Wall -pedantic to compile and I got the following error:
test.cpp: in member function 'void super<b>::foo()': test.cpp:11:3: error: '_attr' was not declared in this scope
source share