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 :
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;
}
Just a basic query, Visual Studio reports:
warning C4553: '==' : operator has no effect; did you intend '='?
I'm just wondering why it says == has no effect when it does successfully compare the two objects.
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!