1

考虑以下代码:

#include <iostream>
#include <type_traits>

template<typename Type>
class Test
{
    public:
        constexpr Test(const Type val) : _value(val) {}
        constexpr Type get() const {return _value;}
        static void test()
        {
            static constexpr Test<int> x(42);
            std::integral_constant<int, x.get()> i;
            std::cout<<i<<std::endl;
        }
    protected:
        Type _value;
};

int main(int argc, char *argv[])
{
    Test<double>::test();
    return 0;
}

在 g++ 4.7.1 下,它返回错误:

main.cpp: In static member function ‘static void Test<Type>::test()’:
main.cpp:13:48: error: invalid use of ‘Test<Type>::get<int>’ to form a pointer-to-member-function
main.cpp:13:48: note:   a qualified-id is required
main.cpp:13:48: error: could not convert template argument ‘x.Test<Type>::get<int>()’ to ‘int’
main.cpp:13:51: error: invalid type in declaration before ‘;’ token

我不明白这个问题:它是编译器错误还是真正的问题?如何解决?

4

1 回答 1

1

它看起来像一个GCC 错误,clang 3.2编译没有任何错误

于 2013-01-10T04:50:30.663 回答