Dereference a pointer in Cxx


#1

Im trying to write an interface to a C++ library using Cxx. I’m running into a problem with pointers. Specifically, I can create a new object like so:

	myObj = @cxxnew Object()

However, I would now like to call a member function of a different class, that takes a parameter of type Object:

	@cxx foo->setObj(myObj)

This does not work, apparently because myObj is in fact a pointer to an Object:

  /Cxx.cpp:1:1: error: reference to type 'const Object' could not bind to an lvalue of type 'Object *'

So it looks like I need to dereference myObj. At least, that’s what I would do if I were writing C++ and not Julia. I cannot for the life of me find a combination of unsafe_load() or unsafe_pointer_to_objref() or any other magic incantations from the Julai C interface or Cxx library to make this work. Any help would be appreciated.


#2

Did you try icxx"foo->setObj($myObj)" ?


#3

Yes, eventually. I was looking for a way to do is using native Julia code, and couldn’t find one. So eventually just writing C++ code directly using icxx is what worked.