Import all variables of the parent class

You may have noticed that later versions of gcc are more stringent with standards ( see this question )

All inherited members of the template class must be called using the full name, i.e. ParentClass<T>::member instead of member

But I have a lot of old code that does not respect this. Adding using ParentClass<T>::member for each element used in each class is a pain. Is there a way to do something like using ParentClass<T>::* ?. I would like it to be better than deactivating this check in g ++, but if there is a way, how to deactivate it?

Edit

According to C ++ frequently asked questions (thanks to sth), this is the only way to correctly resolve the names of inherited variable names:

  • Change the call from f() to this->f() . Since this is always implicitly dependent on the template, this->f depends and therefore the search is delayed until the template is actually created, at which point all base classes will be considered.

  • Paste using B<T>::f ; just before calling f() .

  • Change the call from f () to B<T>::f() .

So, now we are looking for the right switch to deactivate full name resolution ...

+4
source share
1 answer

Not the answer to your question, but you can also write this->member instead of ParentClass<T>::member . This is most often easier to write and makes the compiler look for member in the right place.

+6
source

All Articles