How to do multiple inheritance for Matlab C++ Mex file?

4 次查看(过去 30 天)
Dear all,
I would like to generate multiple Mex-Files that all have a similar structure. They all look somethings like this:
class MexFunction : public matlab::mex::Function {
void operator()(ArgumentList inputs, ArgumentList outputs);
void doSomeThing();
};
The operator function is always the same, but they all differ in the doSomeThing function. My idea was now to declare a base class like this
class MexBaseFunction : public matlab::mex::Function {
void operator()(ArgumentList inputs, ArgumentList outputs);
virtual void doSomeThing() = 0;
};
where I define the common operator() function once and then only change doSomeThing
class MexFunction : public MexBaseFunction {
void doSomeThing() override;
};
This doesn't work, because in order to define the base class, I have to include mexAdapter.hpp where a lot of stuff is going on that need a class called MexFunction.
My second attempt was to use multiple inheritance by defining a class
class MexBaseFunction {
void operator()(ArgumentList inputs, ArgumentList outputs);
virtual void doSomeThing() = 0;
};
that doesn't inherite from matlab::mex::Function. Then my mex-Functions would have the structure
class MexFunction : public matlab::mex::Function, public MexBaseFunction {
void doSomeThing() override;
};
This doesn't work as well, because I need to include various header files in my base class, because there I need ArgumentList, Struct, CellArray etc. In these header files various functions are defined. In my class that defines MexFunction I need to include the same files and, thus, get errors, because some functions are defined multiple times.
Now my question is:
Is there a proper approach to this problem - are forward-declarations a way to go?
Thanks in advance and best regards,
Torsten
  3 个评论
Diego Leal Gonzalez
Diego Leal Gonzalez 2020-11-19
I am having exactly the same problem. Have you found another solution to this?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Write C++ Functions Callable from MATLAB (MEX Files) 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by