This is the error:
error: assigning to 'o.netpp::cMessage *' from incompatible type 'o.netpp::cMessage'`
This is my code:
#include "computer.h"
Define_Module(Computer);
void Computer::initialize() {
counter = 0;
limit = 10;
if (strcmp ("c1", getName())==0) {
simtime_t F_delay = par ("F_delay");
EV<<"Start Sending== \n";
*msg = *createMessage();
scheduleAt(simTime()+ F_delay, *msg);
}
}
Computer::Computer() {
my_msg = nullptr;
}
Computer::~Computer() {
cancelAndDelete(my_msg);
}
void Computer::handleMessage(cMessage *msg) {
if(msg->isSelfMessage()) {
send (msg,"out");
}
else {
counter ++;
if (counter == limit) {
EV<<"Limit is expired \n";
delete msg;
}
else {
EV << " my name "<< getName()<< " \n";
EV << "counter = "<< counter << " \n";
simtime_t delay = par("delay");
scheduleAt(simTime()+delay,msg);
EV << "sending again "<<" \n";
}
}
}
cMessage Computer::createMessage() {
cMessage *msg = new cMessage ("HELLO");
return *msg;
}
void Computer::sendCopyOf(cMessage *msg) {
cMessage *copy= (cMessage *)msg->dup();
send (copy ,"out");
}
This function should return a pointer, otherwise it is leaking memory
cMessage* Computer::createMessage() {
cMessage *msg = new cMessage ("HELLO");
return *msg;
}
This will fix the error you mentioned during this assignment
*msg = *createMessage();
which can just be
msg = createMessage();
and remember when you are done to delete msg
or you will leak it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.