vector of messages in inet

12 views
Skip to first unread message

matin

unread,
Jul 11, 2014, 4:55:12 PM7/11/14
to omn...@googlegroups.com
hi all,
i need to create a vector of messages that is shared between all nodes.(global) therefore i wrote the following code:
in my BasicApp.h:
static std::list<PublicationMsg*> tranmitionPubMsgArray;
in my BasicApp.cc:
Define_Module(BasicApp);
PublicationMsg* BasicApp::tranmitionPubMsgArray;
....
but when i build my simulation,this errors appears:
Error1:  'BasicApp::tranmitionPubMsgArray' has a previous declaration as 'std::list<PublicationMsg*> BasicApp::tranmitionPubMsgArray'
Error2: declaration of 'std::list<PublicationMsg*> BasicApp::tranmitionPubMsgArray' outside of class is not definition [-fpermissive]
Error3: conflicting declaration 'PublicationMsg* BasicApp::tranmitionPubMsgArray'
what is the problem? please guide me. thanks in advance.

matin

unread,
Jul 12, 2014, 7:34:50 AM7/12/14
to omn...@googlegroups.com
please any one help me. thanks.

Ivo Calado

unread,
Jul 12, 2014, 10:02:59 AM7/12/14
to omn...@googlegroups.com
Matin,
    remove the last line of your code ("PublicationMsg* BasicApp::
tranmitionPubMsgArray") and test, please




--
You received this message because you are subscribed to the Google Groups "omnetpp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Ivo Calado

Quidquid latine dictum sit, altum viditur

Putt's Law:
       Technology is dominated by two types of people:
               Those who understand what they do not manage.
               Those who manage what they do not understand.

matin n

unread,
Jul 12, 2014, 10:15:31 AM7/12/14
to omn...@googlegroups.com
thanks for reply. i did it but a new error appears:
Error: undefined reference to `BasicApp::tranmitionPubMsgArray'
Can you tell me what is the problem? thanks again.


--
You received this message because you are subscribed to a topic in the Google Groups "omnetpp" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/omnetpp/yoxmHajY29I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to omnetpp+u...@googlegroups.com.

Ivo Calado

unread,
Jul 12, 2014, 10:38:09 AM7/12/14
to omn...@googlegroups.com
Matin,
   you are correct. I just forgot to test referecing the list.

 In your BasicApp.cc put this:

std::list<PublicationMsg*> BasicApp::tranmitionPubMsgArray;

matin n

unread,
Jul 12, 2014, 11:24:17 AM7/12/14
to omn...@googlegroups.com
thanks a lot. it is correct. thanks.
excuse me how can i read the messages in this list? i can read the message in vector (e.g. tranmitionPubMsgArray[a]->getDestAddress()) 
but i dont now how can i read the elements in the list. thanks for your helps.

matin n

unread,
Jul 12, 2014, 11:25:07 AM7/12/14
to omn...@googlegroups.com
thanks a lot. it is correct. thanks.
excuse me how can i read the messages in this field? i can read the message in vector (e.g. tranmitionPubMsgArray[a]->getDestAddress()) 

Ivo Calado

unread,
Jul 12, 2014, 12:15:07 PM7/12/14
to omn...@googlegroups.com
To iterate over a list you can use either the for_each statement [using functors (C++03) or closures (C++11)] [1] or using a default for statement like below

for(std::list<PublicationMsg*>::iterator i = tranmitionPubMsgArray.begin(); i != tranmitionPubMsgArray.end(); i++) {
    // 'i' is a reference to each position of PublicationMsg*


--
You received this message because you are subscribed to the Google Groups "omnetpp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

matin n

unread,
Jul 12, 2014, 1:00:42 PM7/12/14
to omn...@googlegroups.com
ok, thanks a lot. 
thank you very much.


--
You received this message because you are subscribed to a topic in the Google Groups "omnetpp" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/omnetpp/yoxmHajY29I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to omnetpp+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages