@stungeye wrote:
Hi folks. This is more of a C++ question than anything, but it involves the ofxGui library.
I’d like to wrap a collection of
ofxSlider
objects in a class callParameters
. I’d then like an object of typeParameteres
to be stored as a reference within a number of other objects. (The idea being to allow a bunch of objects to pull tweakable parameters from a shared source.)Things were working fine until I decided that I wanted to ensure const correctness by storing the references to the
Parameters
object as a const reference. This meant that the Parameters slider-getters had to be const, which is turn caused the compiler to complain about their being no suitable conversion betweenconst ofxIntSlider
toint
.Here’s a simplified implementation of the Parameters h:
#include "ofxGui.h" class Parameters { ofxPanel gui_panel; ofxIntSlider avoidance_multiplier; public: Parameters(); void draw(); int get_avoidance_multiplier() const; };
And the associated class implementation:
#include "Parameters.h" Parameters::Parameters() { gui_panel.setup(); gui_panel.add(avoidance_multiplier.setup("Avoidance Multiplier", 4, 0, 15)); } void Parameters::draw() { gui_panel.draw(); } int Parameters::get_avoidance_multiplier() const { // ### THIS IS THE PROBLEM LINE: return avoidance_multiplier; // Works fine when function isn't const. }
Can someone explain to me what I’d need to do to convert
avoidance_multiplier
, which is now aconst ofxSlider
, into theint
stored within it? Your help is much appreciated.
Posts: 2
Participants: 2