0

Why do we need 2 constructors?

21st Apr 2019, 3:01 PM
The C.A.T Show
The C.A.T Show - avatar
3 Respostas
0
~swim~ Does that explanation answer this..? #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; }
21st Apr 2019, 3:45 PM
The C.A.T Show
The C.A.T Show - avatar