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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -