ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Chart virtual destructors
Posted by David Wilson on Sep-30-2015 23:28
I used std::shared_ptr<BaseChart> as a vanilla return type to return various flavors of CD charts(XYCharts and PieCharts) from chart generation methods of my graphical report objects.

I am now wondering if that works. According to the CD headers, BaseChart does not have a virtual destructor. I believe that would mean that deleting a std::shared_ptr<BaseChart> to a derived chart type (PieChart or XYChart) would call the BaseChart destructor, but not the derived class destructor.

So in the block

{ std::shared_ptr<BaseChart> ptr(new Piechart(...)); }

when ptr is destroyed at the end of the block, the PieChart will not be completely destroyed, only the BaseChart members will be destroyed.

Am I correct?

  Re: Chart virtual destructors
Posted by Peter Kwan on Oct-01-2015 07:51
Hi David,

Class BaseChart does have virtual destructor.

It is because Class BaseChart is inherited from class GarbageContainer. GarbageContainer
has virtual destructor, therefore BaseChart has virtual destructor.

Hope this can help.

Regards
Peter Kwan