Answer the question
In order to leave comments, you need to log in
How to fix a leak?
I'm just learning C++, and I'm currently reading about operator overloading. But then I decided to make an addition operation and realized that when creating the third result object, I simply get lost. I thought somehow through the copy constructor to solve the problem, in general I got confused, I don’t understand anything here is the code, help me:
#include <iostream>
using namespace std;
class obj
{
int a;
public:
void show() {cout<<a<<endl;}
obj(){a=5;}
obj(int i){a = i;}
obj operator+(obj xa) //Этот опер-р отдает новый объект, с суммой двух предыдущих.
{
return *new obj (this->a + xa.a);
}
};
int main()
{
setlocale(0,"");
obj one, two;
(one + two).show(); Вот он тут отображает результат и просто теряется.
system("pause");
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question