Passing parameters to the constructor

i’m trying to create an object in the .h file an pass the parameters like this:

SignalManager gestorAmp(45, 100, 0.5);

but it gives me this error:

expected a type specifier

it works fine if i declare it like this:

SignalManager * gestorAmp = new SignalManager(45, 100, 0.5);

can i pass parameters to an object created in .h without declaring it with the new keyword?

thank you

edit: it works if i declare

SignalManager = gestorAmp;

in .h, and in setup():

void ofApp::setup(){
     gestor = SignalManager::SignalManager(45, 100, 0.5);
}

is that the correct way to do it?

You can initilize by using mustache { }. Like this.

SignalManager gestorAmp{ 45, 100, 0.5 };

1 Like

thank you, that worked.
is that the correct way to pass values to the constructor when declaring in the stack?
i’ve googled but don’t fully understand the use of curly brackets in object initialization

It is called list initialization, new from C++11.
Here is some reading.

https://en.cppreference.com/w/cpp/language/list_initialization

2 Likes

thank you @hrs, i’ll give it a look