I'm a little confused. Basically, I've got 2 different resource managers (AudioLibrary and VideoLibrary) that both inherit from a shared BaseLibrary class. This base class contains references to both audio and video. Both audio and video inherit from a parent class called Media.
I'm keeping the data in a map, filled with unique_ptr. But, to my surprise, I've discovered when these pointers are eventually deleted via .erase, only the base destructor for Media is called.
I guess I've missed something, but I thought that the compiler/run-time library would know that it's either pointing to a video or audio and call it's destructor.
Seems not to be the case. I'm forced to do something like this to actually reclaim all my resources:
void AudioLibrary::deleteStream( const std::string &pathFile )
{
auto baseStream = mStreams[ pathFile ].release();
mStreams.erase( pathFile );
// Re-cast!
auto aStream = static_cast<AudioStream*>( baseStream );
delete aStream;
}
Is this normal behavior?
Update:
You're all right - of course it is the missing 'virtual'ness of the destructor. I guess I've recently just thought less and less of what virtual and inheritance means and kind of gotten my head lost in its functionality, rather than the concepts themselves. It happens for me occasionally.