If I have an class with a dynamically allocated array inside of it, how can I return an object from an overloaded addition operator?
The class is basically:
Assume that all myints pointers are dynamically allocated to being 10 integers, which have values...Code:class foo { foo& operator + (foo & myFoo); int *myints; };
Then in the addition I tried
When I try code like this (sorry I don't have the exact code-- I'm on a my laptop at the moment...) I get a warning that I'm returning a reference to a local variable. Is there any way to fix this??Code:foo& foo::operator+ (foo & myFoo) { foo mytemp; //assume mytemp's myints also is correctly allocated as per above... for (int a=0; a < 10; a++) { *(temp.myints + a) = *(myFoo.myints + a) + *(this->myints + a); } return temp; }
thanks!![]()



LinkBack URL
About LinkBacks





