相关疑难解决方法(0)

C++ 11 constexpr函数的参数在模板参数中传递

这曾经在几周前工作:

template <typename T, T t>
T            tfunc()
{
    return t + 10;
}

template <typename T>
constexpr T       func(T t)
{
    return tfunc<T, t>();
}

int main()
{
    std::cout << func(10) << std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但现在g++ -std=c++0x说:

main.cpp: In function ‘constexpr T func(T) [with T = int]’:
main.cpp:29:25:   instantiated from here
main.cpp:24:24: error: no matching function for call to ‘tfunc()’
main.cpp:24:24: note: candidate is:
main.cpp:16:14: note: template<class T, T t> T tfunc()
main.cpp:25:1: warning: control reaches …
Run Code Online (Sandbox Code Playgroud)

c++ gcc metaprogramming constexpr c++11

15
推荐指数
1
解决办法
9241
查看次数

标签 统计

c++ ×1

c++11 ×1

constexpr ×1

gcc ×1

metaprogramming ×1