Skip to main content
GameDev.net gamedev.net
🔒 Locked

boost::shared_ptrBase to boost::shared_ptrDerived

Started by sprite_hound Aug 14, 2008 at 1:53 AM 2 replies 1k views
Original Post
sprite_hound
sprite_hound
Is something like this possible? (I'm leaning towards not, but I just thought I'd make sure...) The code:

class Base {
};
class Derived : public Base {
};

int main(int argc, char* argv[]) {
	boost::shared_ptr<Base> b(new Derived);
	
	boost::shared_ptr<Derived> d(b); // line 25
}


With compiler errors for it:

C:\code_utils\boost-1_34_1\boost\shared_ptr.hpp||In constructor `boost::shared_ptr<T>::shared_ptr(const boost::shared_ptr<Y>&) [with Y = Base, T = Derived]':|
C:\Documents and Settings\Matthew\My Documents\My C++ Projects\testing\toroidalarray\toroidalarray.cpp|25|instantiated from here|
C:\code_utils\boost-1_34_1\boost\shared_ptr.hpp|195|error: invalid conversion from `Base* const' to `Derived*'|
||=== Build finished: 1 errors, 0 warnings ===|


Red Ant
Red Ant
Go here and search for "dynamic_pointer_cast".
sprite_hound
sprite_hound
Ah, thanks Red Ant. Didn't spot that.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.