[C++-sig] Instantiated template class exported to python

Nicolas.Rougier at loria.fr Nicolas.Rougier at loria.fr
Mon Feb 13 21:52:08 CET 2006


I'm trying to define a template class such that I can export
instantiated derived classed with boost. I tried the code included
at the end of this message but it doesn't compile. Error is:

/usr/include/boost/python/object/value_holder.hpp:157: error: no
matching function for call to ‘VecInt::VecInt(PyObject*&, const
core.cc:17: note: candidates are: VecInt::VecInt(const VecInt&)
core.cc:17: note:                 VecInt::VecInt()

I do not quite understand why compiler doesn't found Vec constructors.
Is there something I misunderstood about templates or is there some
misconception in my code (and what would be the right way to do it in
that case) ?


#include <vector>
#include <boost/python.hpp>

using namespace boost;
using namespace boost::python;

template <class T> class Vec : public std::vector<T> {
    Vec (PyObject *self);
    Vec (PyObject *self, const Vec &other);

class VecInt : public Vec<int> {};

class VecInt2 {
    VecInt2 (PyObject *self);
    VecInt2 (PyObject *self, const VecInt2 &other);

namespace boost {
    namespace python {
        template <>struct has_back_reference<VecInt> : mpl::true_ {};
        template <>struct has_back_reference<VecInt2> : mpl::true_ {};

    class_<VecInt> ("VecInt", init<> ());
    //class_<VecInt2> ("VecInt2", init<> ());

More information about the Cplusplus-sig mailing list