On Fri, Jun 8, 2012 at 8:46 AM, christophe jean-joseph <jjchristo...@yahoo.fr> wrote:
> class C > { > public: > double myC; > C(){} > ~C(){} > > void setValue(double val) { > myC = val; > } > > double getValue() { > return myC; > } > }; > ... > > class A > { > public: > ... > C h(){ //This function wont be overloaded in Python > C myC; > this->g(&myC); //We want myC to be modified, and the python overloaded > version of g to be used > C calledC; > double myCint; > myCint = calledC.getValue(); > cout << "Value back in C++: " << myCint << endl; //We want to verify if myC > has been modified back in C++ > myCint = myCint*2; > calledC.setValue(myCint); > return myC; > } > }; > > When I run the code, ... > cout << "Value back in C++: " << > myCint << endl print -9.25596e+061 while I would like the variable to be at > 7. At risk of sounding foolish, your output looks reasonable to me. In A::h(), at the point when you execute that cout << etc., this is all the data that seems to participate: > C calledC; > double myCint; > myCint = calledC.getValue(); > cout << "Value back in C++: " << myCint << endl; You instantiate a brand-new 'C' object calledC. Its constructor doesn't initialize C::myC, therefore it's uninitialized. You then call calledC.getValue(), which returns that uninitialized double. myCint is therefore a strange-looking value. _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig