Try this.
#include <string>class CStudent{public: CStudent(std::string sName, int nClass, int nHouse) { sName = sName; m_nClass = nClass; m_nHouse = nHouse; } std::string m_sName; int m_nClass; int m_nHouse; CStudent *pOpponent1; CStudent *pOpponent2; CStudent *pOpponent3; CStudent *pOpponent4; inline bool operator==(const CStudent &sOpponent) const { return (m_sName == sOpponent.m_sName) }};
by using the expression itself as the return value it makes for more concise code. sOpponent is passed using a reference and const. Passing by reference (that is the & symbol) means that you actually need an object, but when you compare the two values (this is shown in the next bit of code) that a new object is not constructed and destructed. const shows that the object is non-modifiable in the context of the function. The second const shows that you dont modify the object refered to as *this .
Now about calling your equality operator, try this:
CStudent *one = new CStudent("Name", 1, 2);CStudent *two = new CStudent("Name", 1, 2);if(*one == *two) // this line is important{ MessageBox(NULL, "Equal", 0, MB_OK);}delete one;delete two;
This will work because you are comparing the objects not the pointers to the objects. new returns a pointer, not an object. That is you did wrong before, just correct the marked line. The other info I wrote is just better form.
EDIT: I'll remember not to write such a long response next time.