|
-
December 1st, 2008, 08:26 PM
#1
[RESOLVED] More operator problems, please help!
Hi. I've got a problem with this addition operator, that's supposed to concatenate two class objects containing arrays, like so:
c=a+b
where: c.data[15] = a.data[7] + b.data[8]
and: c.size = 15
a.size = 7
b.size = 8
Problem is; my operator adds successfully, but overwrites one of the source classes.
I'm confused as to how you're supposed to utilise two source objects, and then create a 3rd object to hold the result. Can someone please spell it out for me?
This is latest revision, but it creates some sort of cyclical error...
Code:
float_seq &operator+(const float_seq &a)
{
// so create a new object, large enough for both
float_seq temp(number_of_elements+a.number_of_elements);
for(int i=0;i<=(number_of_elements-1);i++) temp.float_seq::write(i,data[i]);
for(int i=0;i<=(a.number_of_elements-1);i++) temp.float_seq::write((i+number_of_elements),a.data[i]);
number_of_elements = number_of_elements+a.number_of_elements;
return (temp);
}
Any help would be greatly appreciated!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|