[C++-sig] How To Determine Return Policy???
chuzo okuda
okuda1 at llnl.gov
Mon Jun 3 20:21:52 CEST 2002
<snip>
And now I got another problem. At the end is a simple source code that
works ok... str1() is working ok, but if static is added, I get
TypeError message *UNLESS* you use str2(Tag*) instead of str2() and
similarly for str3 which issue TypeError. Could you please educate me
why "Tag*" is needed here, even though there is no need if you run in
c++ code... (I found the example code in m1.cpp struct B which uses
name(B*), and I followed this example and it worked... I dont understand
what is going on, since it seems to me that I have to do trial and error
differently many times until it succeeds...).
Thank you
Chuzo
>>> from Test1a import *
>>> t=Tag()
>>> t.str1()
'string return successful'
>>> t.str2()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: bad argument type for built-in operation
>>> t.str3()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: bad argument type for built-in operation
-------------- source ----------------
#include <boost/python/module.hpp>
#include <boost/python/class.hpp>
#include <boost/python/return_internal_reference.hpp>
#include <boost/python/copy_const_reference.hpp>
#include <boost/python/copy_non_const_reference.hpp>
#include <boost/python/return_value_policy.hpp>
#include <string>
class Tag {
public:
Tag():mName("") {}
~Tag() {}
std::string str1() {return "string return successful";}
static std::string str2(Tag*) {return "problem here...";}
static char const* str3(Tag*) {return "work???";}
private:
std::string mName;
};
BOOST_PYTHON_MODULE_INIT(Test1a)
{
using namespace boost::python;
class_<Tag> mod("Tag");
mod
.def_init()
.def("str1", &Tag::str1)
.def("str2", &Tag::str2)
.def("str3", &Tag::str3)
;
module("Test1a").add(mod);
-------------------------------------------
More information about the Cplusplus-sig
mailing list