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>&quot;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.&quot;<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 &quot;flopc.hpp&quot;<br>using namespace flopc;<br><br>&nbsp;&nbsp;&nbsp; class model{<br>&nbsp;&nbsp;&nbsp; public:<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MP_set S1, S2;
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MP_variable * Y;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MP_model * mm; <br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; model(int numS1TimeRange,<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; int numS2<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ~model();<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; void f1();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; void f2();<br>&nbsp;&nbsp;&nbsp; };
<br>#endif<br>----------------------------<br><br>-------model.cpp--------<br>#include &quot;model.hpp&quot;<br>#include &lt;OsiCbcSolverInterface.hpp&gt;<br><br><br>&nbsp;&nbsp;&nbsp; model::model(int numS1,<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int numS2){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; S1= MP_set(numS1);
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; S2 = MP_set(numS2);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mm= new MP_model(new OsiCbcSolverInterface);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Y=new MP_binary_variable(S1);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; };<br><br><br>&nbsp;&nbsp;&nbsp; model::~model(){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; delete mm;
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; delete Y;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; };<br><br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; void model::f1(){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MP_constraint c2;&nbsp;&nbsp; &lt;===will run if this line is commented out.<br>&nbsp;&nbsp;&nbsp; };<br><br><br>&nbsp;&nbsp;&nbsp; void model::f2(){<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MP_constraint c1;
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c1=sum(S1, (*Y)(S1))&lt;=2;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (*mm).add(c1);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (*mm).maximize(sum(S1, (*Y)(S1)));<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout&lt;&lt;&quot;Y size: &quot;&lt;&lt;(*Y).size()&lt;&lt;endl;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (*Y).display();<br>
<br>&nbsp;&nbsp;&nbsp; }<br>--------------------------<br><br>-----main.cpp-------<br>#include &quot;model.hpp&quot;<br>#include &lt;iostream&gt;<br>using namespace std;<br>void main(){<br>&nbsp;&nbsp;&nbsp; int numS1=5;<br>&nbsp;&nbsp;&nbsp; int numS2=9;<br>&nbsp;&nbsp;&nbsp; model m1(numS1, numS2);
<br>&nbsp;&nbsp;&nbsp; m1.f1();<br>&nbsp;&nbsp;&nbsp; m1.f2();<br>&nbsp;&nbsp;&nbsp; <br>}<br>----------------------------<br><br><br><br>