A template is not a class. You need to create an instance of the template (i.e. Ring<int> instead of Ring ).
class_<Ring<int>>("IntRing", init<int>()) .def("insert", &Ring<int>::insert) .def("display_all", &Ring<int>::displayall) ;
Also, the template <class T> part in your source code:
class_<Ring>("Ring") template <class T> // error .def(init<int>()) .def("insert", &Ring::insert) .def("display_all", &Ring::displayall) ;
is a syntax error. This assumes that you expect that you can attach to the template in a general way, which, unfortunately, is not possible. The reason is that templates are created at compile time, i.e. The compiler must know the exact types with which the template will be used. If you interact with python, you cannot know this in advance because it will be determined at runtime.
Under the hood, Boost.Python generates wrapper functions that take PyObject from python and convert them to strongly typed values for your parameters (and the return values return to PyObject s). He can do this only because he knows the types for converting dynamic values to / from.
The best you can do is create a class that is not generic, but works with python objects instead.
EDIT: In response to your comment ("error:" init has not been declared in this area "), I think the problem is that you include only one Boost.Python header. Either #include <boost/python.hpp> , or specify all the other parts that you need (one is init.hpp).
source share