-
December 29th, 2008, 07:52 PM
#1
Functions returning my user-defined class (w/pointer) don't like operator=.
I have a user-defined class containing several integers and a pointer (to an array of values in another user-defined class which does not contain a pointer, and which works fine and has no similar problems) as data elements. I am using g++.
My problem is this:
If I take a function returning my class, e.g.
myClass myFunction()
and attempt to either set a variable equal to it or return it, e.g.
int main()
{
myClass A;
A=myFunction();
}
or
myClass anotherFunction()
{
return myFunction();
}
I get a compiler error from operator=/the copy constructor, respectively. I have overloaded both of these.
The error is that it seems to call myClass(myClass) instead of myClass(myClass&) for the copy constructor and operator=(myClass) instead of operator=(myClass&), and obviously it doesn't like that. I assume the problem is that things are stored at a particular address only temporarily (until the function finishes), but I could easily be wrong.
Why does this happen and how can I fix it?
Thanks!
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
|