小编Wat*_*atu的帖子

嵌套模板和参数推导

可能的重复:
非推导上下文的解决方法

GCC 无法推断出这个“简单”函数的参数。有什么办法可以帮助编译器一点吗?

template<int a> struct A
{
    template<int b> struct B
    {
    };
};

template<int a, int b> void test(typename A<a>::template B<b> param) { }

int main()
{
    A<1>::B<2> b;

    test<1,2>(b); // works
    test(b);      // doesn't work
}
Run Code Online (Sandbox Code Playgroud)

GCC 4.7.1 的错误消息:

test.cpp: In function 'int main()':
test.cpp:15:8: error: no matching function for call to 'test(A<1>::B<2>&)'
test.cpp:15:8: note: candidate is:
test.cpp:8:29: note: template<int a, int b> void test(typename A<a>::B<b>)
test.cpp:8:29: note:   template argument deduction/substitution failed:
test.cpp:15:8: note:   couldn't deduce …
Run Code Online (Sandbox Code Playgroud)

c++ gcc templates

3
推荐指数
1
解决办法
1858
查看次数

标签 统计

c++ ×1

gcc ×1

templates ×1