[C++-sig] Problems using wrapper.hpp to override virtual functions

Tim Spens t_spens at yahoo.com
Thu Jan 17 00:18:00 CET 2008


Here is the simplest example of what I'm trying to do, I hope this is enough the complete
project to quite large.  I'm using wrapper.hpp so that I can use a python handler to handle
callbacks from the c++ code.


      //c++ pure virtual function definition
      virtual void handle(const CLIENT::client_response & rsp) = 0;

      //c++ wrapper for virtual function "handle"
      virtual void handle(client_response const & rsp)
      {
          if(override func_handle = this->get_override("handle")){
                 //I cannot get this section of code to run, from what I understand this would be the callback into python?
              func_handle(boost::ref(rsp));
              cout << "here handle in python" << endl;}
          else{
                 //I currently have a c++ handler which is called here, I would like to use the python handler though.
              this->python_handler::handle(boost::ref(rsp));
              cout << "here handle in c++" << endl;}
      }

      BOOST_PYTHON_MODULE(libclientpy)
      {
          class_<python_client_handler_wrapper, bases<client_handler>, boost::noncopyable >("python_client_handler", init<>())
              .def("handle", &client_handler::handle);
      }

#PYTHON CODE
import libclientpy
handler = libclientpy.python_handler()
client = libclientpy.client(handler, '127.0.0.1', 7900)

class callback(handler):
    def handle(self, x):
        print 'handle python'

azc = addZapCallback()

Traceback (most recent call last):
  File "./test_client.py", line 304, in <module>
    class callback(handler):
Boost.Python.ArgumentError: Error when calling the metaclass bases
    Python argument types in
    python_client_handler.__init__(python_client_handler, str, tuple, dict)
did not match C++ signature:
    __init__(_object*)


I am unsure what is happening here.  I cannot even find a __init__ function in my python_client_handler that has the said arguments? __init__(python_client_handler, str, tuple, dict)

Any ideas?
Tim




      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping




More information about the Cplusplus-sig mailing list