boost::shared_ptr is good for return type when you create a new type
using pimpl idiom, but in practice, it gives me some trouble when used
for covariant return type. code like below:
struct Object
{
public:
virtual ~Object()
{}
};
typedef boost::shared_ptr<Object> ObjectPtr;
struct Cloneable: public Object
{
public:
virtual ~Cloneable()
{}
//virtual Object* Clone() const = 0;// it is ok in this form
virtual ObjectPtr Clone() const = 0;// it is wrong in this form, see
Foo below
};
struct Foo;
typedef boost::shared_ptr<Foo> FooPtr;
struct Foo : public Cloneable
{
//virtual Foo* Clone() const // it is ok in this form
//{
// return new Foo();
//}
virtual FooPtr Clone() const// it is wrong in this form
{
return boost::shared_ptr<Foo>(new Foo());
}
};
so, any advice?
thanks!
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]