“not declared in this scope” error with templates and inheritance [duplicate]

myOption is not a dependent name, i.e. it doesn’t depend on the template arguments explicitly so the compiler tries to look it up early. You must make it a dependent name:

template <typename InterfaceType>
void ChildClass<InterfaceType>::set()
{
     this->myOption = 10;
}

Now it depends on the type of this and thus on the template arguments. Therefore the compiler will bind it at the time of instantiation.

This is called Two-phase name lookup.

Leave a Comment