I am trying to rewrite a code I have written earlier. The code uses cplex concert API;
#include <ilcplex/ilocplex.h>
using namespace std;
ILOSTLBEGIN
int main(){
IloEnv env;
IloModel model(env);
IloVarArray x(env);
IloCplex cplex(model);
return 0;
}
This code (though it doesn't do anything) works... However now i have implemented my own Class and would like to be able to use these functions as well but I don't know how to inizialize them. So this time I have written them in a differnet class called solver.
//solver.h
#ifndef solver_h
#define solver_h
#include <ilcplex/ilocplex.h>
class solver{
public:
IloModel model;
IloNumVarArray x;
IloRangeArray con;
IloCplex cplex;
solver();
solver~();
};
#endif
Then the cpp file
//solver.cpp
#include <ilcplex/ilocplex.h>
#include <vector>
using namespace std;
#include "solver.h"
ILOSTLBEGIN
solver::solver(){
IloEnv env;
IloModel model(env);
IloVarArray x(env);
IloCplex cplex(model);
}
If i add a function to this class e.g. a function that calls x.add(IloNumVar(env)); In the first example this would add an variable to the x(array), but when I have it in a different class I catch "tring to implement empty handle"...
I know I'm doing everything right in the main program, and I also get it to work if I dont have the different Cplex classes in the h.file but then I can only use the same model once and i would want to call the same model several times.
Is there something clearly wrong here (Besides the lack of code, destructors, etc...) in the h.file or?