Not able to destroy TableHeaderComponent

Hi everybody,

I need to personalize a tableHeaderComponent to add some functionalities when the user clicks on the header. I implemented this by declaring a nested class TeXHeader (my application has to do with TeX) which inherits from tableHeaderComponent which overrides the methods I need to override, and by instantiating an object header of this class. Summarizing I have this structure:

class MainContentComponent::TableComponent final : public Component,
												   public TableListBoxModel
     TableComponent(MainContentComponent * owner_ptr) : header(*this) {
          ...other code...
    class TeXHeader final: public TableHeaderComponent{
          TableComponent & tableOwner;
          ...class members...
            TeXHeader(TableComponent& owner) : tableOwner(owner) { ...other code... }
    } header;

However since I implemented the code like this I run into an exception with the following stack call list:

> Grafia.exe!_CrtIsValidHeapPointer(const void * block) Line 1385 C++
Grafia.exe!free_dbg_nolock(void * const block, const int block_use) Line 888 C++
Grafia.exe!_free_dbg(void * block, int block_use) Line 1011 C++
[External Code]
Grafia.exe!juce::ListBox::~ListBox() Line 389 C++
Grafia.exe!MainContentComponent::TableComponent::~TableComponent() Line 35 C++
Grafia.exe!MainContentComponent::~MainContentComponent() Line 759 C++

Can anyone guess why? I tried using unique_pointers instead of references but no luck.

Thanks in advance for the help!

TableListBoxComponent::setHeader takes ownership of the passed in header component. So you should not use a value or smart pointer in your code to own it. You should just do something like table->setHeader(new MyHeaderComponent); Or use a raw pointer to keep a reference of the component for your use. (But you must not delete it in your destructor.)

Thanks a lot! That actually solved the problem (and made my understanding of ownership clearer).