On 7/4/07, Coockie_jr <<a href="mailto:achille.talon@gmail.com">achille.talon@gmail.com</a>> wrote:<br>> <br>> Hi!<br>> I'm currently wrapping a library and I'm having some problems wth call<br>> policies.
<br>> Here is my peace of code that is causing an error.<br>> <br>> class A<br>> {<br>> public:<br>> <br>> <br>> virtual char* toString() = 0;<br>> operator char*(){return toString();}
<br>> };<br>> <br>> py++ gives me the following warning:<br>> <br>> <br>> Warning: char* A::operator char*() [casting operator]<br>> W1050 = The function returns "%s" type. You have to specify a call policies
<br>> Be sure to take a look on Py++ defined call policies:<br>> <a href="http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#py-defined-call-policies">http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#py-defined-call-policies
</a><br>> <br>> I checked the tutorials but I can't figure out how to define a call policy<br>> for this case...<br><br>It depends on what you want:<br><br>* return Python string<br> - in this case exclude casting operator operator, change return type of toString from "char*" to "const char*" and you'll be fine.
Boost.Python will expose the function using default call policies. If you cannot change code, than I suggest you to create small helper function:<br><br>std::string toString( const A& a ){<br> return a.toString()<br>
}<br> <br>and register it instead of the A::toString function ( <a href="http://language-binding.net/pyplusplus/documentation/inserting_code.html">http://language-binding.net/pyplusplus/documentation/inserting_code.html</a>
)<br><br>* If you want user to allow to write to this place, than you should use "return_range"( <a href="http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#return-range">http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#return-range
</a> ) call policies<br><br>HTH<br><br>-- <br>Roman Yakovenko<br>C++ Python language binding<br><a href="http://www.language-binding.net/">http://www.language-binding.net/</a>