Constexpr构造和静态成员不起作用

时间:2013-01-10 04:47:04

标签: c++ c++11 static-methods constexpr

请考虑以下代码:

#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

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

1 个答案:

答案 0 :(得分:1)

它看起来像GCC bug,铿锵3.2 compiles without any error

相关问题