Original Post
Is there any way to combine convariant return types with smart pointers? I currently have some code that is similar to this: I wanted to change the return type of the clone() function to use a smart pointer, but I can't get it to compile because the compiler/language doesn't recognise the covariance as it would for raw pointers... Does anyone know of a technique to bypass this limitation?
struct base
{
public:
virtual base* clone()const = 0;
};
struct derived : base
{
derived* clone()const
{
return new derived;
}
};
struct base
{
public:
virtual std::auto_ptr<base> clone()const = 0;
};
struct derived : base
{
std::auto_ptr<derived> clone()const
{
return new derived;
}
};