Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 929955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:15:23+00:00 2026-05-15T20:15:23+00:00

I am trying to rewrite a code I have written earlier. The code uses

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:15:23+00:00Added an answer on May 15, 2026 at 8:15 pm

    This code:

    solver::solver(){
       IloEnv env;
       IloModel model(env);
       IloVarArray x(env);
       IloCplex cplex(model);
    }
    

    is not initialising your class members – it is creating local variables in the constructor, which will destroyed when the constructor exits. You want something like:

    solver :: solver( IloEnv & env )
          : model( env ), x( env ), cplex( model ) {
    }
    

    then in main:

    int main() {
        IloEnv env;
        solver s( env ); // create solver object
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to rewrite code I've written in matlab in C++ instead. I have
I am trying to rewrite code written in Java to C++, using templates. Here
I have some mutable scala code that I am trying to rewrite in a
I have this code I'm trying to rewrite to c# from a vbs script.
I have some code that performs a deep copy using Object.clone, but I'm trying
I am trying to rewrite some legacy C code and would like to have
I have some code that I'm trying to rewrite. The code is designed to
I'm trying to rewrite some code using the sqldf library in R, which should
I am trying to make some optimized code using SSE2 instructions. Currently, i have
I'm trying to rewrite this code from DI autofac to Ninject 3.0.0.15. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.