vendredi 26 février 2016

Template argument not deduced for inner class

I want to do something like this:

#include <iostream>

template<typename T>
class myclass
{
    T something;
public:
    myclass(T something) : something{ something }
    { }

    struct result
    {
        T value;
    };

    result get_result()
    {
        return{ something };
    }
};

template<typename T>
std::ostream& operator<<(std::ostream& stream, const typename myclass<T>::result& res)
{
    return stream << res.value;
}

int main()
{
    myclass<int> m(0);
    std::cout << m.get_result() << "\n";
}

In this case neither gcc nor msvc find the overloaded stream operator when I put in a result (which is dependent on a templated outer class). Is what I am trying to do even possible?

Aucun commentaire:

Enregistrer un commentaire