When I compile this code (with Visual Studio 2017):
template<class MostDerived>
class BaseClass
{
public:
typename MostDerived::Units DoStuff()
{
MostDerived::Units units;
return units;
}
};
class DerivedClass : public BaseClass<DerivedClass>
{
public:
enum class Units
{
Unit1
};
};
void Invoke()
{
DerivedClass derivedClass;
DerivedClass::Units units = derivedClass.DoStuff();
}
I get an error:
C2039: 'Units': is not a member of 'DerivedClass'.
Experimenting with it, I've determined that the error occurs when DerivedClass::Units
is used as either the result or a parameter to DoStuff()
(so returning the result in a by-reference variable doesn't fix the error). I can use Units in the body of the function with no error.
Is this behavior consistent with C++ 17 or is it a bug in Visual C++?