December 29th, 2008, 07:52 PM
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.
and attempt to either set a variable equal to it or return it, e.g.
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?
Tags for this Thread
Click Here to Expand Forum to Full Width