Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-04-04 12:41:59


Two of us have looked at your question, and we still don't understand

----- Original Message -----
From: "Eric van Riet Paap" <eric_at_[hidden]>

> In C++ I have a class Node, Derived1 and Derived2, where I would like
> to return a pointer to the actual derived instance.

To start with, C++ classes don't return things, only C++ functions do.
Please recheck your entire post for precise wording. Trying to figure
out what you mean makes it hard to help you.

> I now have to cumbersome construct where the C++ return a pointer to a
> and the Python code calls another function of
> the Node class to get the correct derived class. Like so...
> //Node.h
> class Node
> {
> static Node* Self (void) { return (Node*)gpCNode; } //use
> Node.As...() or Global_.Instance() to convert it to the correct
> class-type!!!
> Camera * AsCamera (void) { return (Camera *)this; }
> //class-type convertion
> Mesh * AsMesh (void) { return (Mesh *)this; }
> //class-type convertion
> Light * AsLight (void) { return (Light *)this; }
> //class-type convertion
> };

No dynamic_cast?

Why not write down the C++ header for your classes, and some Python code
which you would like to work with the wrapped versions of those classes,
adding comments wherever there's something problematic?

And please try to arrange your code narrowly so a mail reader does not
wrap it inappropriately.

> //
> def Instance(node):
> return eval('node.As'+node.SuperClassName()+'()')
> What I would like to do is let the Node.Self() function return the
> type but I'm not actacly sure how to proceed.

You want it to return a Python Type object, or just an object of "the
correct type"? WHat is "correct" in this case?


Boost list run by bdawes at, gregod at, cpdaniel at, john at