I want to store C++ objects in a libcpp.map but I can’t get it working. It even doesn’t work on simple integers if I declare the map in the declarations file.
.pxd file:
from libcpp.map cimport map
cdef class MyClass:
cdef map[int,int] store
.pyx file:
cdef class MyClass:
def __cinit__(self):
self.store = map[int,int]()
Following error:
cdef map[int,int] store
^
C++ classes not allowed as members of an extension type,
use a pointer or reference instead
Why is this not working? If I declare it inside a function it’s working fine.
going from the error it seems you need to store a pointer to it and invoke a new version on the heap
so