0
bool Stock::operator== (const Stock& stk){
if ( this->get_resource() == (stk.get_resource()) )
return true;
else
return false;
}
I created this method to overload the operations of a class, but when I prompt pointers of that class and initialize them, I set values and see if one object is equal to another the method that should return TRUE
, since the values are equal, does not return.
int main (){
Stock* stk1 = new Stock();
Stock* stk2 = new Stock();
stk1->set_resource(10);
stk2->set_resource(10);
cout << stk1->get_resource() << endl;
cout << stk2->get_resource() << endl;
if(stk1 == stk2)
cout << "IGUAL" << endl;
return 0;
}
The if
never runs.
Try taking the
this
. The error may be elsewhere in the code.– Maniero