struct deathNote{ uint32_t apples; uint32_t chocolate; uint32_t pages; deathNote operator+(const deathNote &a, const deathNote &b){ deathNote ret_val; ret_val.apples = a.apples + b.apples; ret_val.chocolate = a.chocolate + b.chocolate; ret_val.pages = a.pages + b.pages; return ret_val; } };//struct //ERROR: operator+ must take zero or one argument. //The fix? One parameter is implied via the "this" pointer. //WORKING OVERLOADED OPERATOR: deathNote operator+(const deathNote &a){ deathNote ret_val; ret_val.apples = a.apples + this -> apples; ret_val.chocolate = a.chocolate + this -> chocolate; ret_val.pages = a.pages + this -> pages; return ret_val; }
Goodbye to All That (2014)
9 years ago
No comments:
Post a Comment