Michael Sweet wrote:
> Albrecht Schlosser wrote:
>> ...
>> What happens? Note that img points to an Fl_Shared_Image object.
>> The compiler can't detect this, can it? Will the Fl_Shared_Image
>> be destroyed?
> 
> Yes, it will, since the destructor of a class is always virtual.
> 
>> Will ~Fl_Shared_Image() be called, and what should this do?
> 
> The Fl_Shared_Image destructor will get called.  It *should* remove
> the image from the shared image list.
> 
>> Currently the Fl_Shared_Image would be removed from the image
>> list only if release() would be called, but we'd have a problem
>> anyway, since there might be other pointers to the shared image.
> 
> Yup, and we'll just have to educate users about this - don't use
> delete on shared images, don't mix delete with retain/release, etc.

And that's the reason why I don't *like* the current implementation
of Fl_Shared_Image. IMHO education is not the way to prevent
obvious errors, especially in this case, where we would like to
have polymorphism (in a way that we can use Fl_Image pointers
everywhere), but then we must take care how to destroy the object.
And this should preferably work without dynamic_cast ...

I have some thoughts about a (hopefully compatible) re-implementation,
and I think that I can write a short overview shortly. I'll do this
in another thread though.

Albrecht
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to