Calling a private constructor of


#1

Hi all,

I’ve been trying to use the juce::Array object to hold a dynamic amount of GUI objects “FXChainComponent”.

PluginEditor.h

Array<FXChainComponent> m_FXChainComponents; void addFXChain();

PluginEditor.cpp

[code]void CrossroadsAudioProcessorEditor::addFXChain()
{
//Check to make sure Num of FX Chains is under the custom limit (5)
const int n = m_FXChainComponents.size();
if (n > 5)
return;
//Add new FXChainComponent (append to end of array)
m_FXChainComponents.add(FXChainComponent());

//Return pointer to last element in array & add to editor
addAndMakeVisible(m_FXChainComponents.end());

}[/code]

Everything’s great albeit one error upon compilation: “Calling a private constructor of class ‘FXChainComponent’”

Taking a look at FXChainComponent.h I only see the default (public) constructor.

[code]class FXChainComponent : public Component,
public SliderListener
{
public:
//==============================================================================
FXChainComponent ();
~FXChainComponent();

//==============================================================================
//[UserMethods]     -- You can add your own custom methods in this section.
//[/UserMethods]

void paint (Graphics& g);
void resized();
void sliderValueChanged (Slider* sliderThatWasMoved);

private:
//[UserVariables] – You can add your own custom variables in this section.
//[/UserVariables]

//==============================================================================
ScopedPointer<Slider> m_Slider1;
ScopedPointer<Slider> m_Slider2;
ScopedPointer<Slider> m_Slider3;
ScopedPointer<Label> m_LabelParam1;
ScopedPointer<Label> m_LabelParam2;
ScopedPointer<Label> m_LabelParam3;
ScopedPointer<Label> m_LabelHead;


//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FXChainComponent)

};[/code]

Is there something I missed on the juce::Array? I’ve looked over the documentation several times :oops: Any help would be much appreciated :mrgreen:


#2

Look was JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR does!

This creates a FXChainComponent() as a stack object, and i think the compiler will call the copy-constructor (which is declared as private) when adding this to the array.

I think in this case its easier to work with pointers and use OwnedArray instead Array and then


#3

juce::Array’s fine print clearly states its requirements for the objects you would like to contain: description.


#4

Got it working! Many thanks guys. :smiley: