c++ – no match for ‘operator<<’ in ‘std::operator
c++ – no match for ‘operator<<’ in ‘std::operator
You need to overload operator <<
for mystruct
class
Something like :-
friend ostream& operator << (ostream& os, const mystruct& m)
{
os << m.m_a << << m.m_b << endl;
return os ;
}
See here
Theres only one error:
cout.cpp:26:29: error: no match for ‘operator<<’ in ‘std::operator<< [with _Traits = std::char_traits]((* & std::cout), ((const char*)my structure )) << m’
This means that the compiler couldnt find a matching overload for operator<<
. The rest of the output is the compiler listing operator<<
overloads that didnt match. The third line actually says this:
cout.cpp:26:29: note: candidates are:
c++ – no match for ‘operator<<’ in ‘std::operator
Obviously, the standard library provided operator does not know what to do with your user defined type mystruct
. It only works for predefined data types. To be able to use it for your own data type, You need to overload operator <<
to take your user defined data type.