type can not allocate an object of abstract type

May 19, 2014 at 8:22pm
I have problem with Define_Module.
Error is: can not allocate an object of abstract type 'Q_mgmt_PerVlan' (Q_mgmt_perVlan.cc)

Can anyone pls help?

The code for Q_mgmt_perVlan.cc is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "Q_mgmt_PerVlan.h"

Define_Module(Q_mgmt_PerVlan);

void Q_mgmt_PerVlan::initialize()
{
    // TODO - Generated method body
}

void Q_mgmt_PerVlan::handleMessage(cMessage *msg)
{
    // TODO - Generated method body
    // Self Message
    if (msg->isSelfMessage())
    {
        EV << "Self-message " << msg << " received\n";
        return;
    }


    // Network Message
    cGate *ingate = msg->getArrivalGate();
    EV << "Frame " << msg << " arrived on port " << ingate->getName() << "...\n";

    if (ingate->getId() ==  gate( "in")->getId()){
        send(msg,"out");
    }
    else if (ingate->getId() ==  gate( "out")->getId()){
        send(msg,"in");
    }else{
        EV << "Q_mgmt_PerVlan: Message came FROM THE UnKnown DIRRECTION???? Dropping\n";
        delete msg;
    }
}


void Q_mgmt_PerVlan::requestPacket()
{
   }

bool Q_mgmt_PerVlan::isEmpty(){
    return false;
}


The code for Q_mgmt_perVlan.h is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef __Q_MGMT_PERVLAN_H__
#define __Q_MGMT_PERVLAN_H__

#include <omnetpp.h>
#include <inttypes.h>
#include "IPassiveQueue.h"

class Q_mgmt_PerVlan : public cSimpleModule, public IPassiveQueue
{
  protected:
    virtual void initialize();
    virtual void handleMessage(cMessage *msg);

    virtual void requestPacket();
    virtual bool isEmpty();
};

#endif




May 19, 2014 at 8:30pm
I believe that IPassiveQueue is an abstract interface which contains several pure virtual functions. Do you overloaded all of them?
May 19, 2014 at 8:44pm
Yes, not all but some of them. The code of IPassiveQueue.h is given below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

#ifndef __INET_IPASSIVEQUEUE_H
#define __INET_IPASSIVEQUEUE_H
#include <omnetpp.h>
#include "INETDefs.h"

class IPassiveQueueListener;

/**
 * Abstract interface for passive queues.
 */
class INET_API IPassiveQueue
{
  public:
    virtual ~IPassiveQueue() {}

    /**
     * The queue should send a packet whenever this method is invoked.
     * If the queue is currently empty, it should send a packet when
     * when one becomes available.
     */
    virtual void requestPacket() = 0;

    /**
     * Returns number of pending requests.
     */
    virtual int getNumPendingRequests() = 0;

    /**
     * Return true when queue is empty, otherwise return false.
     */
    virtual bool isEmpty() = 0;

    /**
     * Clear all queued packets and stored requests.
     */
    virtual void clear() = 0;

    /**
     * Returns a packet directly from the queue, bypassing the primary,
     * send-on-request mechanism. Returns NULL if the queue is empty.
     */
    virtual cMessage *pop() = 0;

    /**
     * Adds a new listener to the listener list.
     * It does nothing, if the listener list already contains the listener
     * (by pointer equality).
     */
    virtual void addListener(IPassiveQueueListener *listener) = 0;

    /**
     * Removes a listener from the listener list.
     * It does nothing if the listener was not found on the listener list.
     */
    virtual void removeListener(IPassiveQueueListener *listener) = 0;
};

/**
 * Interface for notifying listeners about passive queue events.
 */
class INET_API IPassiveQueueListener
{
    public:

      virtual ~IPassiveQueueListener() {};

      /**
       * A packet arrived and it was added to the queue (the queue length
       * increased by one). Therefore a subsequent requestPacket() call
       * can deliver a packet immediately.
       */
      virtual void packetEnqueued(IPassiveQueue *queue) = 0;
};

#endif
May 19, 2014 at 8:59pm
You need to overload all pure virtual functions to be able to instantiate your class
Topic archived. No new replies allowed.