Returning objects from C++ to m-script

Problem description

I am trying to speed up some computations by compiling a C++ version instead of programming it directly in m-script. The result is a fairly complex data structure, that I would like to represent as objects.
Is it possible to return objects defined i C++ to m-script? Also calling methods on the returned objects.

My system

  • OS: Windows 10 (version 2004)
  • Octave version: Version 5.2.0
  • Installation method: Downloaded and installed “octave-5.2.0-w64-installer.exe” from

I assume that in general you have to convert your complex object into something Octave can understand, e.g. structs

Best would be a small example of your code :slightly_smiling_face:

Thank you for replying!
If possible, I would prefer to return objects defined in C++ classes, just like the classes work in m-script.

You could go down this road, but it will be a lot easier if you can just re-use existing Octave types. Either cell arrays or structs are the most common data containers and they can hold any other Octave data type including objects.

If you feel that the data must be held in an object on the Octave side then you could write a special constructor in an m-file that knows how to parse the struct or cell array that you return from C++ and populates the member variables appropriately.