Is the class derived from SendData_real_T in ert_main not defined correctly?
4 ビュー (過去 30 日間)
古いコメントを表示
I have a simulink project that I've generated c++ code for using the embedded real time target. Until recently, I've been using 2018b. When I regenerated using 2021a, I see that they have changed the class for message sending from "SendData_doubleT.h" to "SendData_real_T.h". The only difference between the two headers is the new one adds a virtual destructor:
2018b
#ifndef RTW_HEADER_SendData_doubleT_h_
#define RTW_HEADER_SendData_doubleT_h_
#include "rtwtypes.h"
class SendData_doubleT
{
public:
virtual void SendData(const real_T *data, int32_T *status) = 0;
};
#endif
2021a
#ifndef RTW_HEADER_SendData_real_T_h_
#define RTW_HEADER_SendData_real_T_h_
#include "rtwtypes.h"
class SendData_real_T
{
public:
virtual void SendData(const real_T *data, int32_T length, int32_T *status) = 0;
virtual ~SendData_real_T()
{
}
};
After changing the code that uses this simulink model to use SendData_real_T instead of SendData_doubleT, my compiler complained that the class I derived from SendData_real_T was still abstract:
In file included from main.cpp:17:0:
./example.h:87:32: error: cannot declare field Example::SendData_arg to be of abstract type MyModelSendData_real_T
MyModelSendData_real_T SendData_arg;
^
In file included from ./example.h:13:0,
from main.cpp:17:
../../../../MyModelSendData_real_T.h:7:7: note: because the following virtual functions are pure within MyModelSendData_real_T:
class MyModelSendData_real_T : public SendData_real_T{
After simply adding an empty destructor definition in my derived class, the code compiles fine.
When you use the embedded real time target, simulink gives you an example implementation of the code called ert_main in which it also shows you how to derive a class from SendData_real_T, except the example is the SAME (aside from name of class) between 2021a and 2018b:
2018b:
#include <stddef.h>
#include <stdio.h> // This ert_main.c example uses printf/fflush
#include "SM.h" // Model's header file
#include "rtwtypes.h"
class MyModelSendData_doubleT : public SendData_doubleT{
public:
void SendData(const real_T* data, int32_T* status)
{
// Add send data logic here
}
};
static MyModelSendData_doubleT SendData_arg1;
static MyModelSendData_doubleT SendData_arg2;
static MyModelSendData_doubleT SendData_arg3;
static MyModel My_Obj( SendData_arg1, SendData_arg2,SendData_arg3);// Instance of model class
2021a:
#include <stddef.h>
#include <stdio.h> // This ert_main.c example uses printf/fflush
#include "SM.h" // Model's header file
#include "rtwtypes.h"
class MyModelSendData_doubleT : public SendData_real_T{
public:
void SendData(const real_T* data,int32_T length, int32_T* status)
{
// Add send data logic here
}
};
static MyModelSendData_real_T SendData_arg1;
static MyModelSendData_real_T SendData_arg2;
static MyModelSendData_real_T SendData_arg3;
static MyModel My_Obj( SendData_arg1, SendData_arg2,SendData_arg3);// Instance of model class
SO, my final question is: Is there a bug in the Matlab example code since 2021a (or maybe in revisions since 2018b), or is there something else that I'm missing or don't understand?
0 件のコメント
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!