1

Using pybind11, I am trying to bind double pointer to custom type (abstract class). But I am not seeing any example which explains how to do.

I have class ITest which is abstract and has pure virtual function, which takes argument as double pointer to other abstract class IValue, as shown in below code snippet.

    '''
        class IValue
        {
          virtual long get() = 0;
        }
        
        class ITest
        {
        virtual fnDoublePointerarg(wchar_t* value, IValue** obj) = 0;
        }
    '''

How do I create binding for double pointer in pybind for classes? Any examples to achieve it, is appreciated.

More details:

I created a trampoline class as it is abstract class and pybind11 cannot instantiate as below

class PyIValue : public IValue
{
  public IValue::IValue;
  long get(){
    PYBIND11_OVERRIDE_PURE(
            long, 
            IValue,     
            get,          
            );
  }

};

class PyITest : public ITest
{
public:
    using ITest::ITest;
    int fnDoublePointerarg(const wchar_t* domainId, IValue** ppOb)  {
        PYBIND11_OVERRIDE_PURE(
            int, 
            ITest,     
            fnDoublePointerarg,          
            std::wstring domainId,
            IValue** ppOb);
   }
};

PYBIND11_MODULE(Example, m) {
    m.doc() = "pybind11 example plugin"; // Optional module docstring
    
    py::class_<ITest, PyITest>(m, "ITest")
        .def(py::init<>())
        .def("fnDoublePointerarg",ITest::fnDoublePointerarg)

}

SRI
  • 11
  • 3
  • It isn't clear what you mean by "binding" `obj` just needs to be a pointer to a pointer to `IValue` Often, this happens when you have an array of pointers to `IValue` in which case a pointer to that array is what `obj` should be. It may be that the purpose is to alter the pointer to `IValue` perhaps to somehow attach it in Python. – doug Mar 03 '21 at 04:21
  • Thanks for the response. I added more details to the query. I mean PYBIND11_MODULE .def for the function. As it is not compiling. – SRI Mar 03 '21 at 07:33
  • Take a look here - it might help https://stackoverflow.com/questions/66227840/how-to-wrap-class-template-consisting-virtual-function-with-pybind – doug Mar 04 '21 at 02:24

0 Answers0