[C++-sig] Boost.Python - Simple Pointer Question

CLARKE,RON (HP-Vancouver,ex1) ron_clarke at hp.com
Mon Jan 6 20:01:43 CET 2003


I know I've missed something that should be obvious and simple, but ...
We have a medium-sized Python/C++ project and I am investigating replacing
SWIG with Boost.Python (V2). I've read all the documentation more than once,
reviewed the examples, etc. but I still don't see the syntax/macros/commands
needed to allow Python to understand a pointer to an existing C++ class
contained within another class.   Here is a simplified scenario:
 
class car
{
public:
    car(void);
    virtual ~car(void);
private:
... 
};
 
class garage{
public:
    garage(void);
    ~garage(void);
    car* pCar;
};
 
Class garage contains a public pointer to a car object (I don't have the
option of changing the C++ code; it would negatively affect too many users).
I can create garage and car objects OK and Python understands each one:
c=car()
g=garage()
 
However, if I try something like this:
         g.pCar = car()
the resulting object is null and trying to simply print the object yields a
"TypeError: bad argument for built-in operation".
 
What have I missed? Can someone please provide an example (other than what
is in the documentation)?
 
Similarly, if I want to pass a pointer to a C++ object as a parameter to a
C++ function or method, how do I expose the function properly such that a
user can type the function call in Python and have the object properly
passed into the C++ module?
For example: 
     garage.parkTheCar(c)  ## what is the proper Boost.Python syntax for
exposing the parkTheCar method and pointer parameter?
 
Thanks in advance for the help.

_________________________________________ 
Ron Clarke 
Digital Printing Technologies 
Hewlett-Packard Company 
ron_clarke at hp.com 
360-212-0193 

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030106/ad27687a/attachment.htm>


More information about the Cplusplus-sig mailing list