"首先在这里定义" - omnetpp

时间:2017-05-19 19:36:08

标签: c++ omnet++

我是新的 omnet ++ ,并且在 c ++ 方面没有多少经验。我试图创建我的第一个类似于我在教程中找到的项目的模拟,但是我收到了这个错误:

first defined here

几乎在 Message.cpp 中的每个方法旁边(除了 Message::Message(const char *name, int kind) : cPacket(name,kind), getMessageID() and setMessageID())。

* 其他帖子没有解决我的问题。

Message.h:

#ifndef MESSAGE_MESSAGE_H_
#define MESSAGE_MESSAGE_H_

#include <iostream>
#include <sstream>
#include <omnetpp.h>

using namespace omnetpp;

class Message: public ::cPacket{
    protected:
        int src_var;
        int dst_var;
        int sessionID_var;
        int messageID_var;
        int priority_var;
        double creationTime_var;

      private:
        void copy(const Message& other);

      protected:
        // protected and unimplemented operator==(), to prevent accidental usage
        bool operator==(const Message&);

      public:
        Message(const char *name=NULL, int kind=0);
        Message(const Message& other);
        virtual ~Message();
        Message& operator=(const Message& other);

        virtual int getSrc() const;
        virtual void setSrc(int src);
        virtual int getDst() const;
        virtual void setDst(int dst);
        virtual int getSessionID() const;
        virtual void setSessionID(int sessionID);
        virtual int getMessageID() const;
        virtual void setMessageID(int messageID);
        virtual int getPriority() const;
        virtual void setPriority(int priority);
        virtual double getCreationTime() const;
        virtual void setCreationTime(double creationTime);
};

#endif /* MESSAGE_MESSAGE_H_ */

Message.cpp:

#include "Message.h"

Message::Message(const char *name, int kind) : cPacket(name,kind)
{
    this->src_var = 0;
    this->dst_var = 0;
    this->sessionID_var = 0;
    this->messageID_var = 0;
    this->priority_var = 0;
    this->creationTime_var = 0;
}

Message::Message(const Message& other) : cPacket(other)
{
    copy(other);
}

Message::~Message()
{
}

void Message::copy(const Message& other)
{
    this->src_var = other.src_var;
    this->dst_var = other.dst_var;
    this->sessionID_var = other.sessionID_var;
    this->messageID_var = other.messageID_var;
    this->priority_var = other.priority_var;
    this->creationTime_var = other.creationTime_var;
}

int Message::getSrc() const
{
    return src_var;
}

void Message::setSrc(int src)
{
    this->src_var = src;
}

int Message::getDst() const
{
    return dst_var;
}

void Message::setDst(int dst)
{
    this->dst_var = dst;
}

int Message::getSessionID() const
{
    return sessionID_var;
}

void Message::setSessionID(int sessionID)
{
    this->sessionID_var = sessionID;
}

int Message::getMessageID() const
{
    return messageID_var;
}

void Message::setMessageID(int messageID)
{
    this->messageID_var = messageID;
}

int Message::getPriority() const
{
    return priority_var;
}

void Message::setPriority(int priority)
{
    this->priority_var = priority;
}

double Message::getCreationTime() const
{
    return creationTime_var;
}

void Message::setCreationTime(double creationTime)
{
    this->creationTime_var = creationTime;
}

编辑:2

控制台输出:

15:15:58 **** Build of configuration debug for project TIRT ****
make MODE=debug all 
MSGC: message/Message.msg
generator/BasicGenerator.cpp
generator/PoissonGenerator.cpp
message/Message.cpp
message/Message_m.cpp
Creating executable: out/gcc-debug//TIRT.exe
out/gcc-debug//message/Message_m.o: In function `Message::Message(Message const&)':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:192: multiple definition of `Message::Message(Message const&)'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:20: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::Message(Message const&)':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:192: multiple definition of `Message::Message(Message const&)'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:20: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::~Message()':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:197: multiple definition of `Message::~Message()'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:25: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::~Message()':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:197: multiple definition of `Message::~Message()'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:25: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::~Message()':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:197: multiple definition of `Message::~Message()'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:25: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::copy(Message const&)':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:210: multiple definition of `Message::copy(Message const&)'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:30: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::getSrc() const':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:242: multiple definition of `Message::getSrc() const'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:40: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::setSrc(int)':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:247: multiple definition of `Message::setSrc(int)'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:45: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::getDst() const':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:252: multiple definition of `Message::getDst() const'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:50: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::setDst(int)':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:257: multiple definition of `Message::setDst(int)'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:55: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::getSessionID() const':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:262: multiple definition of `Message::getSessionID() const'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:60: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::setSessionID(int)':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:267: multiple definition of `Message::setSessionID(int)'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:65: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::getMessageID() const':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:272: multiple definition of `Message::getMessageID() const'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:70: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::setMessageID(int)':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:277: multiple definition of `Message::setMessageID(int)'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:75: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::getPriority() const':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:282: multiple definition of `Message::getPriority() const'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:80: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::setPriority(int)':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:287: multiple definition of `Message::setPriority(int)'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:85: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::getCreationTime() const':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:292: multiple definition of `Message::getCreationTime() const'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:90: first defined here
out/gcc-debug//message/Message_m.o: In function `Message::setCreationTime(double)':
D:\omnetpp-5.1.1\samples\TIRT/message/Message_m.cpp:297: multiple definition of `Message::setCreationTime(double)'
out/gcc-debug//message/Message.o:D:\omnetpp-5.1.1\samples\TIRT/message/Message.cpp:95: first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:89: out/gcc-debug//TIRT.exe] Error 1

15:16:05 Build Finished (took 7s.819ms)

编辑3.已解决:

出现问题,因为我手动创建了Message类(Message.cppMessage.h)加Message.msg作为&#34;模板&#34;所以编译器有这个问题(多重定义)。这就是当你坐得太久时会发生的事情。

0 个答案:

没有答案