Boost::python wrapper for derived class method
Question: I have C++ class and its wrapper for boost::python:

    
    
    class CApp
    {
     public:
       virtual bool FOOs (){}; //does not matter for now
       bool Run( const char * First,const char * Last) 
       {
         ...
         return "Running..."
       };
    
    struct pyApp : CApp, wrapper<CApp>  //derived class 
    {
       ... // wrappers for virtual methods
    }
    
    #include <boost/python.hpp>
    using namespace boost::python;
    BOOST_PYTHON_MODULE( myApp )
    {
    class_<pyApp, boost::noncopyable>("CApp", init<>()   )
                ...
        .def("Run",&pyMOOSApp::Run);
    }
    

Compiling is OK. But when i'm invoking Python code

    
    
    from myApp import *
    
    class pyApp(CApp):
    def __init__(self):
        print "INIT-->"
    
    CClass = CApp()
    pyClass = pyApp()
    CClass.Run('myApp','bar')
    pyClass.Run('myApp','bar')
    

I have an error:

    
    
    INIT-->
    Running... // this is from CClass.Run
    Traceback (most recent call last):
    File "./pytest.py", line 18, in <module>
    pyClass.Run('myApp','bar')
    Boost.Python.ArgumentError: Python argument types in
    CApp.Run(pyApp, str, str)
    did not match C++ signature:
    Run(CApp {lvalue}, char const*, char const*)
    

So I've tries to write a wrapper for Run method that is converting str to char
placed in derived class c++ code:

    
    
    bool Run(std::string a, std::string b) {
        char * cstrA;
        char * cstrB;
        cstrA = new char[a.size()+1];
        cstrB = new char[b.size()+1];
        strcpy(cstrA,a.c_str());
        strcpy(cstrB,b.c_str());
        return this -> CApp::Run(cstrA, cstrB);
    }
    

But the only change was in the last stroke:

    
    
    did not match C++ signature:
    Run(pyApp {lvalue}, std::string, std::string)
    

**I'm pretty sure that a have bad wrapper for the Run method** , so any help
will be appreciated. Thank you.


Answer: I just saw your other question ([Using derived class (C++) by Python
BOOST](http://stackoverflow.com/q/14076708/82896)) and believe this has the
same solution. You need to call init() on the base class if you provide an
init in the derived class. See my solution here -
<http://stackoverflow.com/a/14742937/82896>.

