在g ++和clang上另一个模板类中定义的模板类的“类型不是类模板”

时间:2019-06-03 17:19:56

标签: c++ templates visual-c++ g++ clang

我正在将一些代码从Windows移植到Linux。我遇到了这样的代码结构:

namespace a
{
    enum b {
        ONE, TWO
    };
}

template <class T>
class X {
public:
    template <a::b Type>
    struct S {};
};

template <class T>
class Y {
public:
    inline void operator=(const struct X<T>::S<a::ONE>& a) {}
    inline void operator=(const struct X<T>::S<a::TWO>& a) {}
};

这是再现错误的最小示例,即:

main.cpp:18:46: error: ‘S’ is not a class template
     inline void operator=(const struct X<T>::S<a::ONE>& a) {}
                                              ^
main.cpp:19:46: error: ‘S’ is not a class template
     inline void operator=(const struct X<T>::S<a::TWO>& a) {}
                                              ^
main.cpp:19:17: error: ‘void Y<T>::operator=(const class X<T>::S&)’ cannot be overloaded
     inline void operator=(const struct X<T>::S<a::TWO>& a) {}
                 ^~~~~~~~
main.cpp:18:17: error: with ‘void Y<T>::operator=(const class X<T>::S&)’
     inline void operator=(const struct X<T>::S<a::ONE>& a) {}
                 ^~~~~~~~

在我的代码中,类和结构中有一些元素,但是它们不会影响此错误。在Windows上的MSVC下,该代码段在g ++和clang下进行编译。要使此代码在所有前面提到的编译器下都能正常工作,需要进行哪些更改?

0 个答案:

没有答案