以下代碼段有什麼問題?候選模板被忽略,因爲無法推斷模板參數
#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);
}
鐺提供了以下錯誤消息:
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.