Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a derived class object with existing base class object?

Is there a possibility of (or fast workaround for) creating an object defined as derived a class without creating base class object in memory; instead the derived object should refer to the actually existing object of base class ("take-over" its memory residence)? This is needed for speed reasons - creating new a derived object, copying data from base class object to it, and then destroying base object takes too much time.

like image 848
theSoon Avatar asked Nov 29 '25 15:11

theSoon


1 Answers

You might want to consider composition instead of inheritance in this case - it would be more natural.

like image 178
brado86 Avatar answered Dec 01 '25 07:12

brado86



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!