【问题标题】:Constexpr construction and static member is not workingConsexpr 构造和静态成员不起作用
【发布时间】:2013-01-10 04:47:04
【问题描述】:

考虑以下代码:

#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

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

【问题讨论】:

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


    【解决方案1】:

    看起来像GCC bug,clang 3.2 compiles without any error

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多