필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
Torsten Knüppel
Torsten Knüppel 2018년 11월 28일
댓글: Diego Leal Gonzalez 2020년 11월 19일
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
Torsten Knüppel
Torsten Knüppel 2019년 3월 2일
Excellent suggestion, thanks a lot.
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