Hello I'm currently analyzing a source code below which works well in Linux (MinGW) but doesn't work in MSVC, visual studio in Windows. This code is following C++ 03 rule, not C++ 11.
template <typename T>
class CTestClass
{
public:
static const int Width = T::Length;
static const typename T::TestType begin = T::begin;
static const typename T::TestType end = T::end;
};
This is the error message in visual studio 2017 (MSVC).
error C2510: 'T': left of '::' must be a class/struct/union
error C2065: 'Length': undeclared identifier
error C2065: 'begin': undeclared identifier
I can see the intention of the code : T can be any class which has static const member variables Length, begin, and end. But the way of expressing is quite awkward to me. From my understanding, this should not work cause T is not supposed to be defined as typename T (but class T), also There should be T instance declared inside CTestClass.. But still this works in Linux somehow.
I wonder
- How this grammar works in Linux(MinGW) but not in MSVC?
- To make this works in Visual Studio in Windows (MSVC compiler), how should I modify that CTestClass ?