Buses as inputs/outputs in C MEX S-Functions and vectors as structure members

2 次查看(过去 30 天)
Hi everybody,
I need help, I've already learned how to define buses as outputs/inputs of a c-mex functions with the legacy code tool but what I need now is that my structures which are actually the buses have vectors as members. Something like :
typedef struct sTestData {
std::vector<Type_A> member1;
std::vector<Type_B> member2;
} TestData_t;
when I try to generate the code for the c-mex function and compile it I receive several errors :
error C2039: '..': is not a member of 'std::vector<_Ty>' with [ _Ty=Type_A ]
I hope someone can help me.

回答(1 个)

Kaustubha Govind
Kaustubha Govind 2012-8-24
First, std::vector is a C++ data structure, so you can't use them inside C S-functions, you'll need to use C++ S-functions. Second, Simulink does not support dynamic allocation, so data structures like std::vectors are not allowed. You might need to convert your std::vectors to built-in arrays (which is fairly easy using an intermediate type and extracting the built-in array under the std::vector using &member1[0]) of fixed-size (or of a fixed maximum size at any rate if you plan to create a bus containing variable-size signals).
  2 个评论
N P
N P 2012-8-24
My mistake, I've wanted to say c++. And how do you suggest to do it? Like :
typedef struct sTestData { Type_A member1[10]; Type_B member2[10]; } TestData_t;
Because in that case the compiler has again problems with the generated c++ code from the LCT. It says :
error C2228: left of '.write' must have class/struct/union. Type is Type_A [10]

请先登录,再进行评论。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by