Hi everyone,
I have a silly question, that I just spent a while on to no avail.
Say I have this in pluginEditor.h:
ShapeButton array[5];
How do I properly initialize it in pluginEditor.cpp?
I keep getting “call to deleted constructor”. I’ve tried using a vector, initializing the array directly in the header file, and initializing array in the initializer of pluginEditor.cpp, but I keep getting the same problem.
There might be some sneaker/cleaner way to do that, but the following does work :
In your editor header declarations :
std::vector<std::unique_ptr<juce::ShapeButton>> shapebuttons;
And in your editor constructor body :
shapebuttons.push_back(std::make_unique<juce::ShapeButton>("but1",juce::Colours::red,juce::Colours::blue,juce::Colours::green));
shapebuttons.push_back(std::make_unique<juce::ShapeButton>("but2",juce::Colours::red,juce::Colours::blue,juce::Colours::green));
shapebuttons.push_back(std::make_unique<juce::ShapeButton>("but3",juce::Colours::red,juce::Colours::blue,juce::Colours::green));
shapebuttons.push_back(std::make_unique<juce::ShapeButton>("but4",juce::Colours::red,juce::Colours::blue,juce::Colours::green));
shapebuttons.push_back(std::make_unique<juce::ShapeButton>("but5",juce::Colours::red,juce::Colours::blue,juce::Colours::green));
for (auto& but : shapebuttons)
{
addAndMakeVisible(*but);
}
peter22
November 1, 2024, 10:09pm
3
Thanks I really appreciate it! Do you know why add make_unique makes this work?
For example, doing something like
std::vector<juce::ShapeButton> shapebuttons;
and
shapebuttons.push_back(juce::ShapeButton("but1",juce::Colours::red,juce::Colours::blue,juce::Colours::green));
does not work. Why is that?
std::vector<juce::ShapeButton> shapebuttons;
Will require the vector elements to be copyable/moveable values, but the Juce components have that explicitly disabled. (It could make quite a mess if Components could be copied around as values.)
Using pointers gets around that issue.
1 Like
I found a related post that was helpful for anyone else interested in learning more.
C++ beginner here.
I created a “Drumpad” class, which is essentially just a component onto which I can drag and drop samples, which then are added to a sampler as a sound.
My idea was to write the class for one pad, and than create something like a “padmatrix” class. This class would simply “have” 127 pads - each of these pads then would automatically correspond to a midi note being played etc. (basically like in abletons drum rack for example).
However when I try to create a vector
std::vec…