Hi there,
I'm just starting to try out Operator Overloading and wrote a basic definition for the equality operator ==.
base.h :
Code:class Base { public: Base (int a); int getNo() const { return m_a; } private: int m_a; }; Base::Base(int a) { m_a = a; } bool operator==(const Base& leftparameter, const Base& rightparameter) { leftparameter.getNo() == rightparameter.getNo(); return true; }
main.cpp :
Just a basic query, Visual Studio reports:Code:#include <iostream> #include "base.h" using namespace std; int main() { Base obj1(1); Base obj2(1); if(obj1 == obj2) { cout << "Objects match" << endl; } else { cout << "Objects don't match" << endl; } system ("pause"); return 0; }
I'm just wondering why it says == has no effect when it does successfully compare the two objects.warning C4553: '==' : operator has no effect; did you intend '='?
I don't see why would it think I meant to assign one object to another.
Should I not worry about it? Or am I missing the point of the warning?
Thanks for any info!



LinkBack URL
About LinkBacks


