Let say I have a class :
class MyIntegers
{
public:
MyIntegers(int sz); //allocate sz integers in _Data and do some expensive stuff
~MyIntegers(); //free array
int* _Data;
}
And this small piece of code :
int sz = 10;
MyIntegers a(sz), b(sz), c(sz);
for (int i=0; i<sz; i++)
{
c._Data[i] = a._Data[i] + b._Data[i];
}
Is it possible to overload a ternary operator+
to replace the loop with c=a+b
without create a temporary object ?
Overload the operator=
and operator+=
and write c=a; c+=b;
to avoid the creation of a temporary object is not acceptable in my case.