http://www.omnetpp.org/doc/omnetpp/tictoc-tutorial/part2.html at tutorial 9 にある OMNeT チュートリアルを進めているときに、いくつかの紛らわしい表記法に出くわしました。
void Tic9::sendCopyOf(cMessage *msg)
{
cMessage *copy = (cMessage *) msg->dup();
send(copy, "out");
}
コードは非常に短くてきれいですが、C++ / OMNeT の経験がほとんどないため、この行が何をするのか理解できませんでした: cMessage *copy = (cMessage *) msg->dup();、より具体的には(cMessage *). 私はmsg->dup()実際に意味を知ってい(*msg).dup()ます。
メモリ内で実際に何が起こっているのか、誰か詳しく教えてください。
ポスト編集補遺:
のコードdup():
virtual cMessage *dup() const
{
return new cMessage(*this);
}
description for dup():このオブジェクトの正確なコピーを作成して返します。これは、返された(cMessage *) msg->dup()オブジェクトのアドレスを内部的に渡す
ことを意味しますか?msg->dup()*copy?
他の紛らわしい表記法:
cMessage *Tic9::generateNewMessage()
{
// Generate a message with a different name every time.
char msgname[20];
sprintf(msgname, "tic-%d", ++seq);
cMessage *msg = new cMessage(msgname);
return msg;
}
*クラス名の前の意味は次のとおりです。*Tic9::generateNewMessage()