可能重复:
Why is the template argument deduction not working here?
Workaround for non-deduced context
请考虑以下代码:
template<typename T>
struct S
{
struct I
{
T t;
};
};
template<typename T>
std::ostream& operator<<(std::ostream& out, const typename S<T>::I& i)
{
out << i;
return out;
}
int main()
{
S<int>::I i;
std::cout << i;
}
此代码在Visual Studio 2010中失败,因为&lt;&lt;无法找到运营商。是否可以为S :: I创建输出运算符?