Well, I'm not sure what I'm doing here, but this is not the case. Trying to overload the class's "==" method, and it just ... doesn't work. At least I get false feedback from mine main, but coutin the implementation '==' does not output.
These are my three files:
#ifndef TESTCLASS_H
#define TESTCLASS_H
class TestClass {
public:
TestClass(int contents);
TestClass(const TestClass& orig);
virtual ~TestClass();
bool operator==(const TestClass& other);
private:
int contents;
};
#endif
#include <iostream>
#include "TestClass.h"
TestClass::TestClass(int contents) {
this->contents = contents;
}
TestClass::TestClass(const TestClass& orig) {
this->contents = orig.contents;
}
TestClass::~TestClass() {
}
bool TestClass::operator ==(const TestClass& other) {
std::cout << "COMPARING" << std::endl;
return (contents == other.contents);
}
#include <cstdlib>
#include <iostream>
#include "TestClass.h"
using namespace std;
int main(int argc, char** argv) {
TestClass* tc = new TestClass(1);
TestClass* tc1 = new TestClass(1);
cout << (tc == tc1) << endl;
return 0;
}
So the question is, what did I do wrong? I apologize for what is probably a very stupid mistake, but I just can’t notice it.
source
share