[C++-sig] Re: Argument handling, char** in constructor

David Abrahams dave at boost-consulting.com
Wed Aug 27 01:31:22 CEST 2003


Wolfgang Langner <wl at flexis.de> writes:

> Hello,
>
> I use boost.python 1.30 with python 2.2.3 under Windows (VC6).
>
> My python module interfaces to a C++ class that has the following
> constructor:
>
> MyClass(int* argc = 0, char** argv = 0);
>
> In boost.python I exposed it with:
> <some stuff> ...
> .def(init<optional<int*, char**> >())
>
> This works only if I have no arguments.
> The problem is, I have to pass arguments from the command line
> (called python programm) to the C++ class. (same as in main())
>
> First I tried to solve it with a small wrapper class that
> inherits from the C++ class and maps a python list of strings
> to that interface. But that don't work because the C++ class
> is a singleton.
>
>
> Are ther any suggestions to expose this class to python ?

Well, what do you expect to be able to pass to this class from Python?
There are no built-in conversions from Python to char**.

I'm guessing you'd like to write:

   >>> MyClass(['arg1', 'arg2'])

??

I have an item on the TODO list which should address that need
(http://www.boost-consulting.com/boost/libs/python/todo.html#injected-constructors)
but I am not precisely sure that it will work for you because of the
"singleton" issue.  What does that mean in your case?  Can MyClass
instances be allocated on the heap?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list