I have a virtual class in my code:
namespace X
{
class Y
{
public:
/* CTOR */
Y() {};
/* DTOR */
virtual ~Y() {};
/* Initialization */
virtual bool Init() = 0;
virtual int Foo(void** ptr, size_t size) = 0;
virtual int Foo2(void *ptr) = 0;
private:
};
}
I need to define the variable in python using cppyy:
std::shared_ptr<X::Y> tempValue = nullptr;
I have tried
self.allocMgr = cppyy.gbl.MEMORY_ALLOCATOR.Allocator.__smartptr__()
It didn't work.
What is not working for you with
cppyy.gbl.std.shared_ptr['X::Y']()?Nominally, using
cppyy.gbl.std.make_sharedis the easiest approach (just as it is for C++), but in this case the template can not be directly instantiated because the class in the example is virtual. However, you can still create a typednullptrusingcppyy.bind_object(cppyy.nullptr, cppyy.gbl.X.Y)which can be used as an argument to aid implicit template instantiations.Note that if
std::shared_ptr<X::Y> tempValue = nullptr;is what you're looking for, and the Python code isn't obvious, then it's always possible to usecppdefas a workaround, eg.: