inheritance and shared_ptr (3)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

inheritance and shared_ptr (3)

Pierre Salmon
Hi again,

My last question was wrong again, ...

In this example:

struct A1 { typedef boost::shared_ptr<A1> TPtr ; } ;
struct A2 { typedef boost::shared_ptr<A2> TPtr ; } ;
struct B : public A1, public A2 {
        typedef boost::shared_ptr<B> TPtr ;
} ;

I want to register those 3 structs to Lua, and have it handle shared_ptr on
them.

void Register () {
        module(L) [
                class_<A1, A1::TPtr>("A1"),
                class_<A2, A2::TPtr>("A2"),
        class_<B, B::TPtr, bases<A1, A2>, A1::TPtr, A2::TPtr>("B"),
        ] ;
}

It fails to compile because we pass 5 arguments to the B class_ registration
call, that can take 4 at max. How can I achieve this?

I already tried to put the A1::TPtr and A2::TPtr in the "bases", but it
doesn't compile either.

Sorry for the two previous posts, cheers,

        Pierre


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: inheritance and shared_ptr (3)

Evan Wies
Pierre,

I'm still not completely clear of what you are trying to do, but here's some comments that might be
relevant.

AFAIK, wrapped class cannot be "held" in more than one shared_ptr.

A1::TPtr and A2::TPtr are not actually bases, so you can't specify them as bases of the wrapped
class.  Also note that the shared_ptrs are not related by any inheritance graph either.

You can't automatically upcast or convert the shared_pointers.  (downcast works though?)

What you CAN do is explicitly make conversion functions and register them.
It is not ideal, but does the trick for many situations:

A1::TPtr toA1( B::TPtr sp ) { return A1::TPtr( sp ); } // C++ can do this conversion
A2::TPtr toA2( B::TPtr sp ) { return A2::TPtr( sp ); } // C++ can do this conversion

shared_ptrs in luabind are great for lifetime management, but get sticky in terms of binding =(

Good luck,
Evan


Pierre Salmon wrote:

> Hi again,
>
> My last question was wrong again, ...
>
> In this example:
>
> struct A1 { typedef boost::shared_ptr<A1> TPtr ; } ;
> struct A2 { typedef boost::shared_ptr<A2> TPtr ; } ;
> struct B : public A1, public A2 {
> typedef boost::shared_ptr<B> TPtr ;
> } ;
>
> I want to register those 3 structs to Lua, and have it handle shared_ptr on
> them.
>
> void Register () {
> module(L) [
> class_<A1, A1::TPtr>("A1"),
> class_<A2, A2::TPtr>("A2"),
>         class_<B, B::TPtr, bases<A1, A2>, A1::TPtr, A2::TPtr>("B"),
> ] ;
> }
>
> It fails to compile because we pass 5 arguments to the B class_ registration
> call, that can take 4 at max. How can I achieve this?
>
> I already tried to put the A1::TPtr and A2::TPtr in the "bases", but it
> doesn't compile either.
>
> Sorry for the two previous posts, cheers,
>
> Pierre
>
>
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user