Here's my code:
Bird *polly = new Bird();
Animal **pollyPtr = &bird;
The previous line is giving me the error in the title. Please tell me how I fi this. :)
> Cannot initialize "BaseClass **" with an rvalue of type "DerivedClass **"
There is no implicit conversion from 'pointer to pointer to derived class' to 'pointer to pointer to base class'.
(If it were to be allowed, it would crate a hole in the type system.)
1 2 3 4 5 6 7 8 9 10 11 12
struct animal { virtual ~animal() = default ; /* ... */ };
struct bird : animal { /* ... */ };
int main()
{
bird b ;
bird* pb = std::addressof(b) ;
animal* pa = pb ; // fine: implicit conversion from bird* to animal*
animal** ppa = std::addressof(pb) ; // *** error: no implicit conversion from bird** to animal**
}