Friend class no longer recognized?


I have a class with a private constructor & destructor, it compiled fine with JUCE 1.5, but now that i tried the tip, i get the following error:

error: ‘AudioSlot::~AudioSlot()’ is private
juce_amalgamated.h:962: error: within this context:

juce_amalgamated.h:6436: error: within this context:

juce_amalgamated.h:6477: error: within this context:

The class is declared as a friend like this:

friend class OwnedArray<AudioSlot>; ....... AudioSlot::~AudioSlot() { if (instance!=0) { AudioProcessorEditor *editor=instance->getActiveEditor(); deleteAndZero(editor); deleteAndZero(instance); } deleteAndZero(audioBuffer); }

noob thanks in advance! :smiley:


Well, it’s quite reasonable for that to happen - deleteAndZero used to be a macro, but now it’s a function, so it’s understandable that it shouldn’t be able to access a private destructor.

There are a whole load of different ways you could work around this - make deleteAndZero a friend function, or just call delete directly. Interesting that you had a problem with ScopedPointer because OwnedArray uses it internally… I might tweak that, or else you’d need to make ScopedPointer a friend class as well as OwnedArray, which seems a bit unnecessary.

But the most important advice would be never to use deleteAndZero or delete! Use stack objects, containment, ScopedPointers, etc manage your lifetimes! If this “instance” thing is a static variable, use the juce_DeclareSingleton stuff to manage it (or better still, find a way to NOT use a static, and make it a ReferenceCountedObject or something!)


thanks for the hints, that helps.