-4

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!

Marji
  • 3
  • 2
  • 1
    "What can I do?" Read your compiler errors. And read a good [book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) to learn C++. Oh, and `__BE_GENERATOR_H` is not a legal name. – Baum mit Augen Jun 17 '14 at 12:25
  • This is not worthy of an answer... it's trivial. Yep you should take your compiler's advice more seriously. Is there a member `initialize()` declared in the class `beeGenerator`? Or are those members declared in a more nested scope? – JorenHeit Jun 17 '14 at 12:28
  • @BaummitAugen Correct me if I'm wrong, but aren't macro's/defines starting with double underscores perfectly legal? Of course they're advised against because the format is reserved for implementation-defined macros... but illegal? – JorenHeit Jun 17 '14 at 12:31
  • 1
    @JorenHeit All names starting with an _Captital or containing __ are reserved for the implementation for any use, you must not use them. See [here](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier/228797#228797) for more information. – Baum mit Augen Jun 17 '14 at 12:32
  • @BaummitAugen That's what I just said. I just thought *illegal* was a bit harsh... – JorenHeit Jun 17 '14 at 12:39
  • I'm a begginer. I'm sorry if it seem a dumb question, but, yes, I had read my compiler errors, i had tried to solve but it doesn't work. I would not post if I could solve by myself. – Marji Jun 17 '14 at 12:55
  • @Marji You have declared all your methods in a nested class `class sPtr` not in class `beeGenerator`! Thus you get the error. Either move the function declarations out from the nested class definition, or prefix your implementations with `beeGenerator::sPtr::`. – πάντα ῥεῖ Jun 17 '14 at 13:09
  • @πάνταῥεῖ thank you so much! – Marji Jun 17 '14 at 13:16

1 Answers1

0

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()
Werner Henze
  • 16,404
  • 12
  • 44
  • 69