c++ - I am having trouble with a simple argument dependent lookup / template type inferencing issue -
i have snippet of code , not understand why std::cout line not compiling... argument lookup / template argument inferencing seems correct...
#include <iostream>  template<typename t> struct {     struct m1     {         t x;     }; };  template<typename t> std::ostream &operator<<(std::ostream &os, typename a<t>::m1 const &o) {     os << o.x;     return os; }   int main() {     a<int>::m1 a;      std::cout << a; // line fails      return 0; } btw i'm trying without declaring operator<<() inline function.
your problem t in non deduced context.  c++ simple pattern match, not invert possibly arbitrary type maps.
imagine there specialization of a<void> set using m1=a<int>::m1.  both int , void valid t <<.  problem intractible in general, c++ refuses try: can pattern match on direct template arguments of argument types.
to want:
template<typename t> struct {   struct m1 {     t x;     friend std::ostream& operator<<(std::ostream& os, m1 const& m1){       return os << m1.x;     }   }; }; learn love koenig operators.
Comments
Post a Comment