   C++ == operator problem
  This is my code:Line l1(10, 4, 6), l2(5, 3, 5);cout << l1 == l2;I get some errors:error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'sml::Line' (or there is no acceptable conversion)1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(650): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(697): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(735): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(782): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(906): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(913): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(920): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(927): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(168): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits> &(__cdecl *)(std::basic_ostream<_Elem,_Traits> &))'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(174): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(181): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(188): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(208): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(short)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(241): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(261): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(int)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(286): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 unsigned int)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(306): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(326): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 unsigned long)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(347): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(367): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(388): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(408): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(428): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(448): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(468): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)'1>   with1>   [1>  _Elem=char,1>  _Traits=std::char_traits<char>1>   ]1>   while trying to match the argument list '(std::ostream, sml::Line)'Line::== is defined as follows:bool Line::operator ==(const Line &r) const{return (Gradient() == r.Gradient()) && (X(0) == r.X(0));}By the way, if I put parantheses around l1 == l2 it works, but I don't like it.Line l1(10, 4, 6), l2(5, 3, 5);cout << l1 == l2; // worksIs there a way to make it work without the parentheses?   
Nope, << has a higher precedence than =;  Thank you!   ;Quote:Original post by sheep19By the way, if I put parantheses around l1 == l2 it works, but I don't like it.Why don't you like it? It adds clarity to the code. Whenever i see two operators used in succession like that, i always feel the need to put parens around the one that takes precedence. Otherwise your not quite sure if the meaning is:cout << (l1 == l2); or (cout << l1) == l2;.(Of course, in this case it's pretty obvious, but that's not always the case)Also, please edit your first post and put the error output in source tags so it doesn't take up ~4 pages of scrolling.   