首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >候选模板被忽略,因为无法推断模板参数的问题?

候选模板被忽略,因为无法推断模板参数的问题?

提问于 2018-01-30 00:24:21
回答 2关注 0查看 977

下面的代码有什么问题?

代码语言:txt
复制
#include <iostream>

template<typename K>
struct A {
    struct X { K p; };
    struct Y { K q; };
};

template<typename K>
void foo(const typename A<K>::X& x, const typename A<K>::Y& y) {
    std::cout << "A" << std::endl;
}

int main() {
    A<float>::X x;
    A<float>::Y y;
    foo(x, y);  
}

错误消息:

代码语言:txt
复制
17:2: error: no matching function for call to 'foo'
        foo(x, y);      
        ^~~
10:6: note: candidate template ignored: couldn't infer template argument 'K'
void foo(const typename A<K>::X& x, const typename A<K>::Y& y) {
     ^
1 error generated.

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档