I’m attempting to create a std::vector of Slider objects for a GUI element, similar to the interface where you can draw harmonics in Ableton’s operator synth. Whenever I try to explicitly reference any default constructor, including Slider(), but also oddly including the ones I write myself, I’m told by the compiler that I cannot access that private member. Slider::Slider() is definitely listed under public functions in juce_Slider.h, so what am I missing, some embarrassingly simple C++ feature?
my function (resizeSliders is in a custom Component class auto-generated by the Projucer):
void ProbCurveEditorComponent::resizeSliders(int newNumSliders) { int old = sliders.size(); sliders.resize(newNumSliders, Slider()); // <-- ERROR HERE for (old; old < sliders.size(); old++) { sliders[old].setSliderStyle(juce::Slider::LinearBarVertical); sliders[old].setRange(0, 1, 0.0001); sliders[old].setValue(0); //TODO: addlistener addAndMakeVisible(sliders[old]); } //update draw resized(); }
Command line output: 1>D:\Program Files\VS19\VC\Tools\MSVC\14.24.28314\include\xmemory(671,1): error C2248: 'juce::Slider::Slider': cannot access private member declared in class 'juce::Slider' 1>D:\Program Files\JUCE\JUCE\modules\juce_gui_basics\widgets\juce_Slider.h(993): message : see declaration of 'juce::Slider::Slider' 1>D:\Program Files\JUCE\JUCE\modules\juce_gui_basics\widgets\juce_Slider.h(53): message : see declaration of 'juce::Slider' 1>D:\Program Files\VS19\VC\Tools\MSVC\14.24.28314\include\xmemory(1498): message : see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,const juce::Slider&>(_Alloc &,_Objty *const ,const juce::Slider &)' being compiled 1> with 1> [ 1> _Alloc=std::allocator, 1> _Ty=juce::Slider, 1> _Objty=juce::Slider 1> ] 1>D:\Program Files\VS19\VC\Tools\MSVC\14.24.28314\include\xmemory(1498): message : see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,const juce::Slider&>(_Alloc &,_Objty *const ,const juce::Slider &)' being compiled 1> with 1> [ 1> _Alloc=std::allocator, 1> _Ty=juce::Slider, 1> _Objty=juce::Slider 1> ] 1>D:\Program Files\VS19\VC\Tools\MSVC\14.24.28314\include\xmemory(1722): message : see reference to function template instantiation 'void std::_Uninitialized_backout_al<_Alloc>::_Emplace_back(const juce::Slider &)' being compiled 1> with 1> [ 1> _Alloc=std::allocator 1> ] 1>D:\Program Files\VS19\VC\Tools\MSVC\14.24.28314\include\xmemory(1722): message : see reference to function template instantiation 'void std::_Uninitialized_backout_al<_Alloc>::_Emplace_back(const juce::Slider &)' being compiled 1> with 1> [ 1> _Alloc=std::allocator 1> ] 1>D:\Program Files\VS19\VC\Tools\MSVC\14.24.28314\include\vector(1581): message : see reference to function template instantiation 'juce::Slider *std::_Uninitialized_fill_n<std::allocator>(juce::Slider *,unsigned __int64,const juce::Slider &,_Alloc &)' being compiled 1> with 1> [ 1> _Alloc=std::allocator 1> ] 1>D:\Program Files\VS19\VC\Tools\MSVC\14.24.28314\include\vector(1579): message : while compiling class template member function 'juce::Slider *std::vector<juce::Slider,std::allocator>::_Ufill(juce::Slider *,const unsigned __int64,const _Ty &)' 1> with 1> [ 1> _Ty=juce::Slider 1> ] 1>D:\Program Files\VS19\VC\Tools\MSVC\14.24.28314\include\vector(1233): message : see reference to function template instantiation 'juce::Slider *std::vector<juce::Slider,std::allocator>::_Ufill(juce::Slider *,const unsigned __int64,const _Ty &)' being compiled 1> with 1> [ 1> _Ty=juce::Slider 1> ] 1>D:\Documents\CustomVST\probcurv\Source\ProbCurveEditorComponent.h(30): message : see reference to class template instantiation 'std::vector<juce::Slider,std::allocator>' being compiled 1>Done building project "probcurv_SharedCode.vcxproj" -- FAILED.