Class Definition:
Expand|Select|Wrap|Line Numbers
- class BDay
- { //Should Be Global Scope
- bool operator==( const BDay & , const BDay &);
- bool operator!=( const BDay & , const BDay &);
- friend ostream & operator<<( ostream &, const BDay &);
- public:
- ...
- ...
- ...
- private:
- ...
- ...
- ...
- }
- Member Defintion:
- bool operator!=( const BDay & lhs, const BDay & rhs )
- {
- if (lhs.getName() != rhs.getName()|| lhs.getDay() != rhs.getDay()||
- lhs.getMonth()!= rhs.getMonth())
- return true;
- else
- return false;
- }
- bool operator==( const BDay & lhs, const BDay & rhs )
- {
- return !(lhs != rhs);
- }
Bloodshed Dev C++:
28 C:\Dev-Cpp\CS311\bday.h `bool BDay::operator==(const BDay&, const BDay&)' must take exactly one argument
29 C:\Dev-Cpp\CS311\bday.h `bool BDay::operator!=(const BDay&, const BDay&)' must take exactly one argument
In Visual Studio C++ 2008 Express Edition:
1>c:\dev-cpp\cs311\bday.h(29) : error C2804: binary 'operator ==' has too many parameters
1>c:\dev-cpp\cs311\bday.h(30) : error C2804: binary 'operator !=' has too many parameters
It's obvious in the Dev error that the compiler is assuming that the overloaded '!=' and '==' are member functions with one too many parameters though they are declared globally.
Thanks for any help