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

1 vue (au cours des 30 derniers jours)
Torsten Knüppel
Torsten Knüppel le 28 Nov 2018
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 commentaires
Torsten Knüppel
Torsten Knüppel le 2 Mar 2019
Excellent suggestion, thanks a lot.
Diego Leal Gonzalez
Diego Leal Gonzalez le 19 Nov 2020
I am having exactly the same problem. Have you found another solution to this?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Call C++ from MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by