$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] [smart pointer] need .get() to access derived class method?
From: Diederick C. Niehorster (dcnieho_at_[hidden])
Date: 2010-01-25 00:56:13
Hi All,
I am trying to wrap my head around using shared pointer, but I find
the documentation hard to follow, not being a professional programmer.
I have a base class, from which many classes are derived and I hold
the derived class instance as a point of type baseclass. Usually, I
only need access to the base class methods, but now i need to access
some of the derived class's methods. How do I do that from a shared
pointer?
I now have some mix of shared_pointer and "old style" pointer logic in
my code, what am I missing?
--- _pcStim = boost::shared_ptr<CStim>(new CStimUniform2D()); // create derived instance and store as base CStim* pCStimU = _pcStim.get(); // get raw pointer ((boost::shared_ptr<CStimUniform2D>)(_pcStim))->setNPointGround()=300; // this does not work, what do I need here? ((CStimUniform2D*)pCStimU)->SetPointColor()=_pRoomData->dotColor(); // casting the raw pointer I am fine. --- Best regards and thank you for your reply, Diederick Niehorster