Template dependent inherited typedefs and MSVC

早过忘川 提交于 2019-12-13 02:11:41

问题


A few weeks ago I wrote a trait class for 2d entities like this:

template<typename T>
struct traits_2d
{
    typedef T coordinates_type;
    typedef vector_2d<T> position_type;
    typedef vector_2d<T> direction_type;
    typedef vector_2d<T> size_type;
};

The trait class was used as follows:

template<typename T>
struct aabb_2d : public traits_2d<T>
{
    position_type origin;
    size_type size;
};

The Standard says that template dependent names must be fully qualified, so this should not compile. Of course GCC compilation fails and says something like:

Expected nested-name specifier. Could be 'typename traits_2d<T>::position_type'.

But, on the other hand, I was using this pattern for two weeks in MSVC11 (Visual Studio 2012) and it works and compiles fine.

Why seems like MSVC11 does not follow this language rule?

NOTE: This question is not a duplicate of Propagating 'typedef' from based to derived class for 'template' or its duplicates, it asks about why something that should be an error works in MSVC.

来源:https://stackoverflow.com/questions/19940190/template-dependent-inherited-typedefs-and-msvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!