+ 1
operator overloading C++
#include <iostream> using namespace std; class MyClass { public: int var; MyClass() { } MyClass(int a) : var(a) { } MyClass operator+(MyClass &obj) { MyClass res; res.var= this->var+obj.var; return res; } }; int main() { MyClass obj1(12), obj2(55); MyClass res = obj1+obj2; cout << res.var; } Please helppp. Why missing the âMyClass() { }âin line 7 will cause error??
5 Answers
+ 2
Why is it requiredđ¤Does it have any special meaning?
+ 2
Thx~