Inside my class I have defined the == operator as a friend :
friend bool operator==(rational a, rational b);
bool operator==(rational a, rational b)
{
return a.num==b.num && a.denom==b.denom;
}
ok now when i do
cout<<a == b;
i get this error:
main.cpp
1>c:\users\adrian\documents\visual studio 2010\projects\proiect 1\proiect 1\main.cpp(12): error C2679: binary '==' : no operator found which takes a right-hand operand of type 'rational' (or there is no acceptable conversion)
1> could be 'built-in C++ operator==(void *, void *)'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\exception(470): or 'bool std::operator ==(const std::_Exception_ptr &,const std::_Exception_ptr &)'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\exception(475): or 'bool std::operator ==(std::_Null_type,const std::_Exception_ptr &)'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\exception(481): or 'bool std::operator ==(const std::_Exception_ptr &,std::_Null_type)'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\system_error(408): or 'bool std::operator ==(const std::error_code &,const std::error_condition &)'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\system_error(416): or 'bool std::operator ==(const std::error_condition &,const std::error_code &)'
1> c:\users\adrian\documents\visual studio 2010\projects\proiect 1\proiect 1\rational.h(103): or 'bool operator ==(rational,rational)'
1> c:\users\adrian\documents\visual studio 2010\projects\proiect 1\proiect 1\rational.h(104): or 'bool operator ==(rational,int)'
1> c:\users\adrian\documents\visual studio 2010\projects\proiect 1\proiect 1\rational.h(105): or 'bool operator ==(int,rational)'
1> while trying to match the argument list '(std::basic_ostream<_Elem,_Traits>, rational)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.66
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========