2

I created a new safety messsage that is extended from the DemoSafetyMessage:

import veins.modules.messages.DemoSafetyMessage;
namespace veins;
packet NewSafetyMsg extends DemoSafetyMessage {
double senderAngle;
double PowRxdBmAvg;
}

I include this new message into the MyVeinsApp application and pass it to the onBSM function in both the .cc and .h files of MyVeinsApp.

#include "veins/modules/messages/NewSafetyMsg_m.h"

void onBSM(NewSafetyMsg* bsm) override; // in the .h file

#include "veins/modules/messages/NewSafetyMsg_m.h" //in the .cc file

However, I am getting this error in the .h file.

Description Resource    Path    Location    Type ‘void veins::MyVeinsApp::onBSM(veins::NewSafetyMsg*)’ marked ‘override’, but does not override MyVeinsApp.h    /veins/src/veins/modules/application/traci  line 50 C/C++ Problem

I know that MyVeinsApp is extending the DemoBaseApplLayer which takes DemoSafetyMessage, So there should be no problem!! What I am doing wrong?

Fady Samann
  • 115
  • 7

2 Answers2

1

void onBSM(DemoSafetyMessage* bsm) override; //parent class

void onBSM(NewSafetyMsg* bsm) override; //child class

Function overriding in C++ does'nt work with parameter mismatch.

Pasha M.
  • 340
  • 1
  • 12
  • Yes, I know that from the inheritance. So, what is the correct way to use a new message in an OMNET++/veins project extended from the Demo application? – Fady Samann Feb 23 '22 at 05:56
1

From TraciDemo11p example:

  1. In .h file you need to keep the same method as that of parent class

    void onBSM(DemoSafetyMessage* bsm) override;

  2. In .cc file The extended message (i.e. NewSafetyMessage) should be dynamically casted to parent message type (i.e. DemoSafetyMessage)

    void MyVeinsApp::onBSM(DemoSafetyMessage* bsm)

    {

    NewSafetyMessage* bsm1 = check_and_cast<NewSafetyMessage*>(bsm);

    ......

    ......

Pasha M.
  • 340
  • 1
  • 12
  • Thank you, for the answer. I discovered this yesterday. However, what is the different between dynamic_cast and check_and_cast ?? – Fady Samann Feb 24 '22 at 13:57
  • From OMNET++ documentation:. check_and_cast() is used to Cast an object pointer to the given C++ type and throw exception if fails. The method calls dynamic_cast(p) where T is a type you supplied; if the result is NULL (which indicates incompatible types), an exception is thrown. You may refer the omnet++ doc for more info. – Pasha M. Feb 25 '22 at 07:13