Although I have been using shared_ptr's for a while, I still get a bit
confused with polymorphic stuff ...no change there.
An pseudocode example:
Class A
{
};
Class B : public A
{
DoStuff1();
DoStuff2();
DoStuff3();
DoStuff4()
};
// MyFunction handles A and classes derived from A
MyFunction(shared_ptr<A>)
{
};
Main()
{
shared_ptr<A> polyDoStuff1();
dynamic_pointer_cast<B>(poly)->DoStuff2();
dynamic_pointer_cast<B>(poly)->DoStuff3();
dynamic_pointer_cast<B>(poly)->DoStuff4();
// Or this?
shared_ptr<B> tmp = dynamic_pointer_cast<B>(poly); // is this right?
// I have to create a new pointer?
tmp->DoStuff1();
tmp->DoStuff2();
tmp->DoStuff3();
tmp->DoStuff4();
}
So, the quesiton is one of efficiency - if I was using pointers, I would
just new a B and assign to a B* variable, then pass in to the function
which would use it as an A - no temp required. With above a new tmp
pointer seems to be required - am I right or have I missed something
blindingly obvious.
James
This message (including any attachments) contains confidential
and/or proprietary information intended only for the addressee.
Any unauthorized disclosure, copying, distribution or reliance on
the contents of this information is strictly prohibited and may
constitute a violation of law. If you are not the intended
recipient, please notify the sender immediately by responding to
this e-mail, and delete the message from your system. If you
have any questions about this e-mail please notify the sender
immediately.