c++ - How to return a dynamic object from operator function? -
I am writing an operator function - where my class object is a dynamic array of integers, operator takes Lieutenant and RAS object and Moves the object which is the set of elements in the LAS, but not the rhs.
Although I have written a function but I am unable to return the set because right after the district object is called.
IntegerSet & amp; IntegerSet :: operator - (IntegerSet & amp; rhs) const {IntegerSet Temp); // Local object elements are designed to store the same size as lhs int k = 0; Int lhssize = element (); // no set in the elements of rhssize = rhs.ElementSize (); For (int i = 0; i & lt; lhssize; i ++) {for (int j = 0; j & lt; rhssize; j ++) {if (rhs.ptr [j]! = Ptr [i ]) {k ++; }} If (k == rhssize) {temp = temp + ptr [i]; } K = 0; } Return temporary; } And here is the creator if you can not understand the object
IntegerSet :: IntegerSet (const int and size) // works correctly {Capacity = size; Ptr = new int [capability] (); } IntegerSet :: IntegerSet (const and size) // works correctly {capability = size; Ptr = new int [capability] (); } IntegerSet :: IntegerSet (Constant Integrate and Copy): Capability (copy.capacity) // works correctly {ptr = copy.clonemaker (); } IntegerSet :: ~ IntegerSet () {Capacity = 0; Remove [] ptr; } Int * IntegerSet :: clonemaker () const // works correctly {if (ptr == NULL) {return NULL; } int * tempptr = new int [ability]; {Tempptr [i] = ptr [i]; (for int i = 0; i & lt; capacity; i ++); } Return Tempptr; } You need to change the value to return the value.
IntegerSet IntegerSet :: operator - (IntegerSet & amp; rhs) const In addition to taking context for this, Will make more sense for them.
Comments
Post a Comment