Smart pointers and polymorphism
- by qwerty
hello.
I implemented reference counting pointers (called SP in the example) and im having problems with polymorphism which i think i shouldn't have.
In the following code:
SP<BaseClass> foo()
{
// Some logic...
SP<DerivedClass> retPtr = new DerivedClass();
return retPtr;
}
DerivedClass inherits from BaseClass. With normal pointers this should have worked, but with the smart pointers it says "cannot convert from 'SP<T>' to 'const SP<T>&" and i think it refers to the copy constructor of the smart pointer.
How to i allow this kind of polymorphism with reference counting pointer?
I'd appreciate code samples cause obviously im doing something wrong here if im having this problem.
Thanks! :)
[p.s., plz don't tell me to use standart liberary with smart pointers cuz that's impossible at this moment.]