I recently came across a Visual C ++ compiler compatibility mode switch in VS 2017. I read this explanation , which talked about how the switch can prevent compilation of incompatible code
template<typename T> struct B { int f(); }; template<typename T> struct D : B<T> { int g(); }; template<typename T> int D<T>::g() { return f();
In the definition of D :: g, the symbol f is found from the dependent base class B , but standard C ++ does not allow you to examine the dependent base when looking for ads that satisfy the use of f. That is a bug in the source code that Visual C ++ has long been unable to diagnose.
Alright, alright, I get it. Except one. What for?
Why does the standard not allow the study of a dependent base class for f ()? What is the justification for this ban. Does the standard give one?
If B and D were both regular and non-structural structures, f () would be correctly interpreted as a call to a member function of the base class (er ... base struct). So why is this not done when they are templates?
(I'm sure there is a good reason, but with my limited understanding at the moment it just seems annoying. I tried to find on this issue and found at least one question regarding this, but no one with a “why” of it)
source share