Minimal example:
#include <iostream>
using namespace std;
class myint{
public:
    int x;
    myint(int x) { this->x = x;}
    ~myint() {cout << "DEL" << endl; }
    myint operator += (int const &y) { this->x += y; return y;}
};
int main() {
    myint i = myint(2);
    i += 3;
}
I'm confused why the object i is destructed twice. How do I avoid this? I will have large objects and will want to optimize the code. I do not want new objects creating when using basic operators.
 
     
    