Search code examples
c++classns2

no ‘void beeGenerator::initialize()’ member function declared in class


Ohayou.

I've had read about this error in many topics before asking, but I couldn't solve this by myself. I'm sorry for bother about it.

My problem is:

I have two files, one is a .cpp and other a .h file.

My cpp file is:

#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;
}

My .h file is:

#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

and the errors are

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()

What can I do? :(

Thanks!


Solution

  • If you have

    class beeGenerator 
    {
        class sPtr{
            virtual void initialize_sptr();
        }
        virtual void initialize_bee();
    }
    

    you need to keep the nesting in the implementation, so you must implement it as

    void beeGenerator::initialize_bee()
    {
    }
    void beeGenerator::sPtr::initialize_sptr()
    {
    }
    

    In your case you forgot the sPtr::, so just change your code to for example

    void beeGenerator::sPtr::initialize()