Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
  • After you have changed the makefile (if needed), open a terminal in its directory and type make
  • Then you can execute the script array_py.py
  • You can also open a python terminal in the directory of cpp.so and type import cpp
  • You can create an object of the C++ class with C = cpp.Array_cpp(5)
  • You can then call the member functions of the class : C.set_array(array), C.compute_exponent(), C.get_array()

You can define your own classes in c++ but you have to let boost know that you want to use them in Python :

BOOST_PYTHON_MODULE(cpp)
{
    Py_Initialize();
    np::initialize();
    p::class_<Array_cpp>("Array_cpp", p::init<int>())
        .def("set_array", &Array_cpp::set_array)
        .def("get_array", &Array_cpp::get_array)
        .def("compute_exponent", &Array_cpp::compute_exponent)
    ;
}

More info

Please read Python_Programming/Extending_with_C for more details For more information about adding you own functions or class, here for functions not in a class and in a class