Namespaces parameters

Hello!
I am trying to organize my code since it is becoming too big!!
My simplified main.cpp is:

int main(int argc, char **argv)
{
ampl::AMPL ampl;
setAMPL::readData(ampl);
return 0;
}

Then I have a setAMPL.h file with

#include “ampl/ampl.h” *
namespace setAMPL
{
extern ampl::Parameter iP_tSwi;

void readData(ampl::AMPL &in_ampl);
}
#endif

and a setAMPL.cpp where I would like to set the parameter and function:

#include <setAMPL.h>

ampl::Parameter setAMPL::iP_tSwi;

void setAMPL::readData(ampl::AMPL &in_ampl)
{
in_ampl.read(“./src/ampl/dynamic.mod”);
setAMPL::iP_tSwi = in_ampl.getParameter(“t_swi”);
setAMPL::iP_tSwi.set(10); *
}

I’d like to do this since I might need to modify iP_tSwi in another function after solving…however I get an error

setAMPL.cpp:7:26: error: no matching function for call to ‘ampl::Parameter::Parameter()’
7 | ampl::Parameter setAMPL::iP_tSwi;

What am I doing wrong?? Can use an ampl::Parameter with extern as I would do with a double??

Thank you in advance :slightly_smiling_face:

Have a nice day
Sam

Hi @Samuele_Viaro,

ampl::Parameter does not have an empty constructor so you can’t create a global ampl::Parameter. Can you provide some details about what you are trying to accomplish? Typically most of the actions performed with the APIs require passing all data to AMPL and then retrieving the solution. Some update operations may also happen when solving multiple instances after changing some parameters. All of this usually happens in a single function or class with multiple methods interacting with the same AMPL object.