Ohayou。
在询问之前,我已经阅读了许多主题中的这个错误,但我自己无法解决这个问题。我很抱歉打扰它。
我的问题是:
我有两个文件,一个是.cpp,另一个是.h文件。
我的cpp文件是:
#include "beeGenerator.h"
void beeGenerator::initialize()
{
myAddress = par("address");
sleepTime = (double) par("sleepTimeAtStart");
beeGenInterval = (double) par("iaTime");
beeLength = (int) par("beeLength");
bID = 0;
packetCount = 0;
debug = true;
logResults = par("logResults");
const char *statModulePath = (char*) par("statModulePath");
launchNewBees = new cMessage("launchNewBees");
scheduleAt( simTime() + sleepTime, launchNewBees);
}
void beeGenerator::handleMessage ()
{
if(dynamic_cast<samplePacket *> (msg) != NULL)
{
samplePacket *dPacket = dynamic_cast<samplePacket *> (msg);
delete dPacket;
packetCount++;
if( (packetCount % packetInterval) == 0)
{
packetCount = 1;
launchNewBeeAgents();
}
}
else if (msg == launchNewBees)
{
launchNewBeeAgents();
if(simTime() >= 30.0 )
{
scheduleAt(simTime() + beeGenInterval, launchNewBees);
}
else
{
scheduleAt(simTime() + 1.0, launchNewBees);
}
}
}
void beeGenerator::launchNewBeeAgents()
{
char msgName[70];
sprintf(msgName,"Bee%d : Source%d", bID, myAddress);
beeAgent *bMsg = new beeAgent(msgName);
bMsg->setBID(bID++);
bMsg->setSourceAddress(myAddress);
bMsg->setKind(static_cast<int> (NETLAYER_BEE_AGENT));
bMsg->setSourceModule(BEE_GEN_MODULE);
bMsg->setLength( BYTE * beeLength);
send(bMsg,"toRouter");
}
int beeGenerator::getBID()
{
return bID;
}
void beeGenerator::setBID(int id)
{
bID = id;
}
void beeGenerator::finish()
{
ev << "*** Module: " << fullPath() << "***" << endl;
ev << "Stack allocated: " << stackSize() << " bytes";
ev << " (includes " << ev.extraStackForEnvir() << " bytes for environment)" << endl;
ev << "Stack actually used: " << stackUsage() << " bytes" << endl;
}
我的.h文件是:
#ifndef __BEE_GENERATOR_H
#define __BEE_GENERATOR_H
#include "beeInclude.h"
class beeGenerator
{
class sPtr{
bool debug;
bool logResults;
double beeGenInterval;
double sleepTime;
int beeLength;
int myAddress;
int bID;
int packetCount;
virtual void initialize();
virtual void handleMessage();
virtual void finish();
virtual void launchNewBeeAgents();
int getBID();
void setBID(int id);
};
};
#endif
,错误是
protoname/beeGenerator.cc:3:31: error: no ‘void beeGenerator::initialize()’ member function declared in class ‘beeGenerator’
void beeGenerator::initialize()
^
protoname/beeGenerator.cc:21:35: error: no ‘void beeGenerator::handleMessage()’ member function declared in class ‘beeGenerator’
void beeGenerator::handleMessage ()
^
protoname/beeGenerator.cc:49:39: error: no ‘void beeGenerator::launchNewBeeAgents()’ member function declared in class ‘beeGenerator’
void beeGenerator::launchNewBeeAgents()
^
protoname/beeGenerator.cc:62:26: error: no ‘int beeGenerator::getBID()’ member function declared in class ‘beeGenerator’
int beeGenerator::getBID()
^
protoname/beeGenerator.cc:67:33: error: no ‘void beeGenerator::setBID(int)’ member function declared in class ‘beeGenerator’
void beeGenerator::setBID(int id)
^
protoname/beeGenerator.cc:72:27: error: no ‘void beeGenerator::finish()’ member function declared in class ‘beeGenerator’
void beeGenerator::finish()
我该怎么办? :(
谢谢!
答案 0 :(得分:0)
如果你有
class beeGenerator
{
class sPtr{
virtual void initialize_sptr();
}
virtual void initialize_bee();
}
您需要在实现中保持嵌套,因此必须将其实现为
void beeGenerator::initialize_bee()
{
}
void beeGenerator::sPtr::initialize_sptr()
{
}
在您的情况下,您忘记了sPtr::
,因此只需将代码更改为例如
void beeGenerator::sPtr::initialize()