Array of subclassed Component


#1

Hi - Just getting started on using the Juce framework…

Having trouble with Array::add() because I read classes subclassed from Component shouldn’t have a copy constructor…

So we have:

[code]class CTrackComponent : public Component
{
public:
//==============================================================================
CTrackComponent ();
~CTrackComponent();

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

:
//==============================================================================
juce_UseDebuggingNewOperator

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

//==============================================================================

:

//==============================================================================
// (prevent copy constructor and operator= being generated..)
CTrackComponent (const CTrackComponent&);
const CTrackComponent& operator= (const CTrackComponent&);

};[/code]

If I now have:

[code]class PsplayerAudioProcessorEditor : public AudioProcessorEditor,
public Timer
{
public:
PsplayerAudioProcessorEditor (PsplayerAudioProcessor* ownerFilter);
~PsplayerAudioProcessorEditor();

:

void timerCallback();
void resized();

//==============================================================================
// This is just a standard Juce paint method...
void paint (Graphics& g);

private:
Label infoLabel;

ScopedPointer<CTrackComponent> pTrack;

ScopedPointer<CTrackComponent> pTrack2;

Array<CTrackComponent> TrackArry;

AudioPlayHead::CurrentPositionInfo lastDisplayedPosition;

PsplayerAudioProcessor* getProcessor() const
    {
    return static_cast <PsplayerAudioProcessor*> (getAudioProcessor());
    }

void displayPositionInfo (const AudioPlayHead::CurrentPositionInfo& pos);

};[/code]

and

[code]PsplayerAudioProcessorEditor::PsplayerAudioProcessorEditor (PsplayerAudioProcessor* ownerFilter)
: AudioProcessorEditor (ownerFilter),
infoLabel (String::empty)
{
// This is where our plugin’s editor size is set.
setSize (960, 610);

File szBackgroundImagePath("/Users/railrogut/juce projects/xxxxx/resources/MainBackground.png");

backgroundImage = ImageFileFormat::loadFrom(szBackgroundImagePath);

// add a label that will display the current timecode and status..

addAndMakeVisible (&infoLabel);
infoLabel.setColour (Label::textColourId, Colours::blue);

pTrack = 0;

pTrack2 = 0;

pTrack = new CTrackComponent();
pTrack2 = new CTrackComponent();

if (pTrack)
    pTrack->setTopLeftPosition(5, 84);

if (pTrack2)
    pTrack2->setTopLeftPosition(82, 84);

addAndMakeVisible(pTrack);
pTrack->setSize(75, 521);

addAndMakeVisible(pTrack2);
pTrack2->setSize(75, 521);

// TrackArry.add(*pTrack);

startTimer(50);

}[/code]

the above works… but now if I try and make my CTrackComponent an Array and uncomment:

// TrackArry.add(*pTrack);

(or use the Array add() method on a Constructor derived object) I get a problem because the add() method attempts to call a copy constructor for CTrackComponent and gives a compile error “Calling a private constructor of class CTrackComponent”.

I know I read in the docs somewhere that if you subclass Component you shouldn’t have a copy constructor as it’ll cause problems…

So the question is (finally)… what’s the suggested methodology to create an Array of Components (or their derivatives)?

Thanks,

Rail


#2

juce::OwnedArray?


#3

Thank you sir!

For some reason at 5am this morning I missed that.

Just tested - and works perfect!

Cheers,

Rail