[C++-sig] wrapping vector of pointers

martin manduch martin.manduch at gmail.com
Tue Jan 26 13:36:13 CET 2010


Hi,

I need to wrap vector of pointers, because it's parameter in one function...

I have following code:

struct X
{
    X(int nn) {n=nn;}
    int n;
};


BOOST_PYTHON_MODULE(myVector)
{
    class_<X>("X", init<int>())
    .def_readwrite("n", &X::n);


    class_<std::vector<X*> >("XVec")
        .def(vector_indexing_suite<std::vector<X*> >())

    ;
}

I want to make XVec responsible for memory, which is addressed through
pointers, but I don't know how.

>>vec=XVec()
>>a=X(7)
>>vec.append(a)
>>del a
>>vec[0].n
It prints 1682309121, but I want it to print: 7

Martin


More information about the Cplusplus-sig mailing list