[C++-sig] Re: How to specify a double return type?
Ralf W. Grosse-Kunstleve
rwgk at yahoo.com
Tue Mar 23 16:10:09 CET 2004
--- brett hartshorn <bhartsho at yahoo.com> wrote:
> Thanks Ralf and Nicolas for answering my first question. boost::noncopyable
> fixed my problem!
>
> Sadly, dReal is a typedef. I have tried to make 'thin wrappers' but i am not
> sure if i'm doing it
> right. Here's an example, Foo is the class i am wrapping, Bar is my thin
> wrapper.
>
> typedef double dReal;
>
> class Foo {
> public:
> const dReal * getSomething() const {
> return otherFunction();
> }
>
> };
> class Bar : public Foo {
> public:
> const double * getSomething() const {
> return Foo::getSomething();
> }
> };
You are making a "thick wrapper". And as far as Boost.Python is concerned there
is no difference between wrapping Foo::getSomething and Bar::getsomething.
I believe you have to do something like this (untested):
// a thin wrapper
double
Foo_getSomething(Foo const& foo_instance)
{
return *foo_instance.getSomething(); // dereference the pointer
}
class_<Foo>("Foo")
.def("getSomething", Foo_getSomething)
;
You can .def an unbound C++ function as a Python method. Cool?
In Python foo_instance.getSomething() returns the *current* value of your
dReal. If the value inside your Foo class changes you have to call
foo_instance.getSomething() again to see the change in Python. E.g. instead of
holding on to the const double* (as you might in C++) you have to hold on to
the foo_instance instead.
HTH,
Ralf
__________________________________
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html
More information about the Cplusplus-sig
mailing list