c++ - Error: cannot bind 'std::ostream {aka std::basic_ostream<char>} -


i searched through qs couldn't find answer.

i wanted overload operator<< doesn't work me.

#include <iostream> #include <string> #include <tuple>  class foo { public:     std::tuple<int, float> tp;     foo(int _a, float _b)     {          std::get<0>(tp)=_a;          std::get<1>(tp) =_b;     }      friend std::ostream& operator<<(std::ostream & strm, const std::tuple<int, float> &tp)     {          strm << "[ "<<std::get<1>(tp)<<", "<<std::get<0>(tp)<<"]"<<"\n";          return strm;     } };  int main ()  {    foo a(1, 3.0f);   std::cout<<a;   return 0; } 

error:

cannot bind 'std::ostream {aka std::basic_ostream<char>}' lvalue 'std::basic_ostream<char>&&'      std::cout<<a;                 ^ 

update solved, @juanchopanza

in order call std::cout<<a;, need overload output stream operator has foo second parameter. example:

friend std::ostream& operator<<(std::ostream& strm, const foo& foo)  {   return strm << "[ " << std::get<1>(foo.tp) << ", "               << std::get<0>(foo.tp) << "]" << "\n"; } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -