ostream operator<<对于模板化类的子类

时间:2012-01-18 14:03:26

标签: c++ templates iostream

  

可能重复:
  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创建输出运算符?

0 个答案:

没有答案