Derived class with shared pointers and .def_readwrite
Nigel Atkinson <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <1264601535.2602.34.camel@finwe> |
I think I've found a problem when having a derived classes and using
smart pointers to hold them.
Having:
class A
{
};
class B : public A
{
public:
int x;
};
and binding with:
module(L)
[
class_< A, shared_ptr<A> >( "A" )
.def( constructor<>() ),
class_< B, A, shared_ptr<A> >( "B" )
.def( constructor<>() )
.def_readwrite( "x", &B::x )
];
then running the Lua code:
b = B()
b.x = 1234
results with the error:
No matching overload found, candidates:
void <unknown>(B&,int const&)
The error disappears if you either:
a) Don't use shared_ptr
b) Don't tell luabind that B is derived from A, i.e. in the second class
binding, remove the base class and change the shared pointer to B.
Oh, and while I remember in the docs in section 8.7 at the end it says
"base" where it should say "derived". I've attached a patch.
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
docs.rst.patch
(text/x-patch, 432 B)
--- docs.rst~ 2010-01-07 22:51:11.351893288 +1300
+++ docs.rst 2010-01-28 02:46:16.038580848 +1300
@@ -887,7 +887,7 @@
[
class_<base, boost::shared_ptr<base> >("base")
.def(constructor<>()),
- class_<derived, base, **boost::shared_ptr<base>** >("base")
+ class_<derived, base, **boost::shared_ptr<base>** >("derived")
.def(constructor<>())
];