
Eugene Wee wrote:
Hi,
On Thu, Oct 22, 2009 at 5:26 AM, Ireneusz Szpilewski <irek@szpilewski.opole.pl> wrote:
And how exactly are you supposed to make that change at runtime?
What do you suggest?
heart as a member of Me?
Before:
class Me { MyHeart heart; };
After:
class Me { SomebodyElsesHeart heart; }
It can't be done at runtime either.
If MyHeart and SomebodyElsesHeart publicly inherited from say, a Heart (abstract) base class, and if Me's heart member variable was a (smart) pointer to Heart, then you could indeed change the actual (sub)type of the Heart object that a Me object owns at runtime. This is a common technique, methinks.
Regards, Eugene _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
So, what do you suggest? Heart* as a member of Me? Let's try: struct Me { Me() { heart = new(MyHeart); } ~Me() { delete heart; } private: Heart* heart; }; What if MyHeart has SingMySong() method while Heart does not? How can I access it? Ireneusz Szpilewski