c++ - Polymorphism with smart pointers? -
i've searched bit couldn't find answers correctly problem (i've read this, this , this )
i'm trying use smart pointers polymorphism.
when try create smart pointer abstract class pointer implementation, i.e. :
std::shared_ptr<abstract> ptr = std::make_shared(new implementation); my compiler (msvc2012) displays errors creating instance of abstract not possible because has pure virtual, though try create pointer implementation.
i might use smart pointers wrong in case, don't know did wrong (and visual studio doesn't underline line mentionned).
i wonder if possible use smart pointers when polymorphism needed, , if yes, how must done.
note : know covariance, , fact shared_ptr not type inherit shared_ptr, thought smart pointers handle this.
edit :
as requested, real line of code :
std::shared_ptr<ispectrometer> ret = std::make_shared<oospectrometer>(m_spectrowrapper); with oospectrometer inherit abstract class ispectrometer (and m_spectrowrapper simple parameter).
the error msvc gives me (it's in french, different english message)
error c2259: oospectrometer : can't instantiate abstract class due following members : and lists pure virtual functions in ispectrometer .
the problem not broken behavior of std::shared_ptr respect polymorphism, , error message pretty clear:
error c2259:
oospectrometer: can't instantiate abstract class due following members :
your class oospectrometer cannot instantiated because abstract. likely, not implement pure virtual functions defined in ispectrometer interface.
also, list of pure virtual member functions not overridden oospectrometer should part of error message getting ("due following members: ...").
Comments
Post a Comment