Hello group.<br><br>I create a class, which maintains a MP_model as a member. In two separate methods of this class, I define two constraints and add them to the MP_model. At runtime, my program generates a runtime failure. Here is the error message
<br><br>"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result <br>of calling a function declared with one calling convention with a function pointer declared with a different calling
<br>convention."<br><br>I am using Visual C++ 2005 Express. The source codes are attached below. Can someone please point out what the problem is and how to solve it?<br><br>An interesting observation is that if I comment out a MP_constraint declaration is method f1(). The program will run without error even this declaration seems to have nothing to do with another method f2(), which declare another MP_constraint and maximize a simple objective.
<br><br>Thanks,<br>Paul<br><br>------model.hpp----------------<br>#ifndef _model_hpp_<br>#define _model_hpp_<br><br>#include "flopc.hpp"<br>using namespace flopc;<br><br> class model{<br> public:<br><br> MP_set S1, S2;
<br> MP_variable * Y;<br> MP_model * mm; <br><br> model(int numS1TimeRange,<br> int numS2<br> );<br><br> ~model();<br><br> void f1();<br> void f2();<br> };
<br>#endif<br>----------------------------<br><br>-------model.cpp--------<br>#include "model.hpp"<br>#include <OsiCbcSolverInterface.hpp><br><br><br> model::model(int numS1,<br> int numS2){<br> S1= MP_set(numS1);
<br> S2 = MP_set(numS2);<br> mm= new MP_model(new OsiCbcSolverInterface);<br> Y=new MP_binary_variable(S1);<br> <br> };<br><br><br> model::~model(){<br> delete mm;
<br> delete Y;<br> };<br><br> <br> void model::f1(){<br> MP_constraint c2; <===will run if this line is commented out.<br> };<br><br><br> void model::f2(){<br><br> MP_constraint c1;
<br> c1=sum(S1, (*Y)(S1))<=2;<br> (*mm).add(c1);<br><br> (*mm).maximize(sum(S1, (*Y)(S1)));<br> cout<<"Y size: "<<(*Y).size()<<endl;<br> (*Y).display();<br>
<br> }<br>--------------------------<br><br>-----main.cpp-------<br>#include "model.hpp"<br>#include <iostream><br>using namespace std;<br>void main(){<br> int numS1=5;<br> int numS2=9;<br> model m1(numS1, numS2);
<br> m1.f1();<br> m1.f2();<br> <br>}<br>----------------------------<br><br><br><br>