c++-sig@python.org
[Top] [All Lists]

Re: [C++-sig] call policies help needed

Subject: Re: [C++-sig] call policies help needed
From: "Roman Yakovenko"
Date: Thu, 25 May 2006 06:40:22 +0300
On 5/25/06, Neal Becker <ndbecker2@xxxxxxxxx> wrote:
> Is there something wrong with this, which looks simpler to my (naive) eyes?:
>
> struct A {};
>
> struct B {
>   B (A& _a) : a (_a) {}
>   A& a;
> };
>
> static A& getA (B& b) {
>   return b.a;
> }

getA is defined under global scope. If you add another class
struct C {
  C (A& _a) : a (_a) {}
  A& a;
};

Then you will have to distinct between getA for B and C classes.
Defining those functions
within relevant class wrapper eliminates the problem.

> BOOST_PYTHON_MODULE(demod4)
> {
>   class_<A> ("A");
>   class_<B> ("B", init<A&>()
>                         [with_custodian_and_ward<1,2>()])
>     .def ("getA", &::getA, return_internal_reference<>())

Member variable "a" is not really internal reference. Class "B" does not manage
it's life time.

http://boost.org/libs/python/doc/v2/return_internal_reference.html

>     ;
> }
>



-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
_______________________________________________
C++-sig mailing list
C++-sig@xxxxxxxxxx
http://mail.python.org/mailman/listinfo/c++-sig

<Prev in Thread] Current Thread [Next in Thread>