有没有一种方法可以推断嵌套类中的外部模板?
template<class T>
struct A{
struct B{};
};
template<class T> void f(typename A<T>::B b){} // hard to deduce T?
int main(){
A<double>::B b;
f(b); // no matching function for call to 'f(A<double>::B&)', meant to call f<double>(b);
}
还是我被迫在外面声明嵌套类? 这是唯一的解决方法吗?
template<class T> struct B_impl{};
template<class T>
struct A{
using B = B_impl<T>;
};
template<class T> void f(B_impl<T> b){} // to bad there is no mention of A here
int main(){
A<double>::B b;
f(b);
}