0

I am currently porting some code from Visual studio to mingw and their are instances in the code when variables in the base class are being used inside the methods in a derived class. For instance

template<typename t>
struct base_foo 
{
  int foo;
};

template<typename t>
struct derived_foo : public base_foo<t> 
{
  void some_method();
};

template<typename t>
void derived_foo<t>::some_method()
{
  foo = 12 ; //Error variable not declared in this scope
  base_foo<t>::foo = 12 ; //OK
}

Now there are many instances like this in my code and wanted to know if there was a way for me to state that if there is a variable that isnt found locally look in the base class. In short if the following gives an error

   foo = 12 ; 

then try

base_foo<t>::foo = 12;
MistyD
  • 16,373
  • 40
  • 138
  • 240
  • 1
    Instead of `base_foo::`, you could use `this->` as well. – dyp Mar 25 '15 at 22:42
  • The better option is to fix all your broken code. Note you can also say `this->foo`. – juanchopanza Mar 25 '15 at 22:43
  • Actually, [this](http://stackoverflow.com/questions/4643074/why-do-i-have-to-access-template-base-class-members-through-the-this-pointer) might be the better dupe. – Pradhan Mar 25 '15 at 23:10

0 Answers0