[C++-sig] class_, HeldType, and NonCopyable...please help !!
Stefan Seefeld
seefeld at sympatico.ca
Fri Mar 4 03:41:58 CET 2005
hello,
I'm trying to wrap an API but having problems at runtime that
I can't quite figure out how to resolve. Let me describe the
situation:
My API deals with pointers referring to objects that are
garbage collected. The objects are always created by factories
and never directly allocated via 'new'.
It thus seemed natural to declare
class_<Node, Node *> node("Node", no_init);
but this produced an error because of Node having abstract
methods. Fair enough. My next attempt was to instruct bpl
that 'Node' can't be copied:
class_<Node, Node *, boost::noncopyable> node("Node", no_init);
That compiles. However, I also have a 'Visitor' class with
a 'visit(Node *)' method that I expose, and implement as
class VisitorWrapper : public Visitor
{
public:
...
virtual void visit(Node* n) { call_method<void>(self, "visit", n);}
...
};
The call to "visit" above, when executed, results in the exception:
"TypeError: No to_python (by-value) converter found for C++ type: Node"
and here I'm lost. Going back to the documentation I find:
NonCopyable
If supplied, must be boost::noncopyable.
Suppresses automatic registration of to_python
conversions which copy T instances. Required when T
has no publicly-accessible copy constructor.
(on http://boost.org/libs/python/doc/v2/class.html)
However, 'T' here is 'Node', not the HeldType 'Node *', and so I wonder
how I can a) suppress the need for N's copy-constructor *and* b) have
to_python conversions generated for the *HeldType*, i.e. 'Node *'.
Can anybody help ?
Thanks a lot !
Stefan
More information about the Cplusplus-sig
mailing list