www.digitalmars.com         C & C++   DMDScript  

c++ - problem with boost::shared_ptr<abstract>(concretederived)

reply dan <dan_member pathlink.com> writes:
Example code from
http://www.boost.org/libs/smart_ptr/sp_techniques.html
ST: "Using abstract classes for implementation hiding"

//--------------------------- X.hpp:
class X
{
public:
virtual void f() = 0;
virtual void g() = 0;
protected:
~X() {}
};
shared_ptr<X> createX();
//-------------------------- X.cpp:
class X_impl: public X
{
private:
X_impl(X_impl const &);
X_impl & operator=(X_impl const &);
public:
virtual void f()
{
// ...
}
virtual void g()
{
// ...
}
};
shared_ptr<X> createX()
{
shared_ptr<X> px(new X_impl);
return px;
}
//------------------------------

Doesn't compile in DM, 8.38; says that
it cannot create abstract class.
Even if I say...

shared_ptr<X> createX()
{
shared_ptr<X_impl> px(new X_impl);
return static_cast< shared_ptr<X> >(px);
}

I still get the same message.

dan
Dec 23 2003
parent dan <dan_member pathlink.com> writes:
Update: If I leave the pure virutal functions...

//--------------------------- X.hpp:
class X
{
public:
virtual void f() = 0;
virtual void g() = 0;
protected:
~X() {}
};
..undefined, like... //--------------------------- X.hpp: class X { public: virtual void f(); //// = 0; virtual void g(); //// = 0; protected: ~X() {} }; ..that seems to get around the problem; it compiles nicely. dan
Dec 23 2003