3

Possible Duplicate:
Why is the template argument deduction not working here?
Workaround for non-deduced context

Consider the following code:

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;
}   

This code fails in Visual Studio 2010, as the << operator cannot be found. Is it possible to create an output operator for S::I?

Community
  • 1
  • 1
Petter
  • 37,121
  • 7
  • 47
  • 62
  • 3
    I had [exactly the same problem](http://stackoverflow.com/questions/8308213/workaround-for-non-deduced-context) recently.The cause is that `S::I` is a non-deduced context. – Björn Pollex Jan 18 '12 at 14:06
  • Thanks, I suppose it is better to close this question. – Petter Jan 18 '12 at 14:26

0 Answers0