Std::map

33 views
Skip to first unread message

Sheena

unread,
Jun 23, 2013, 2:00:11 AM6/23/13
to ns-3-...@googlegroups.com
Hey everyone,
I want to store the address with some mapped value.I am doing all these changes in sta-wifi-mac.cc.For that I am using std::map.But I am getting error.
Mac48Address address=hdr->GetAddr3();
And then I am making struct(for mapped value)
struct record {
        double r;
                } ;
      std::map < Ptr<address>, record > ;
The error  am getting is
‘address’ cannot appear in a constant-expression. I am not geting how to make pointer for this variable.

Please help me out.

Thanks.

Junling Bu

unread,
Jun 23, 2013, 4:31:51 AM6/23/13
to ns-3-...@googlegroups.com
hi, Mac48Address cannot use Ptr if you know ns3::Object, ns3::ObjectBase, ns3::SimpleRefCount.
if you want to use map, see below:
struct record {double r;} ;
int
main (int argc, char *argv[])
{
    Mac48Address a;
    struct record r;
    std::map < Mac48Address *, struct record > map ;
    map.insert(std::make_pair(&a,r));
}

However, I think it's safer without pointer.
struct record {double r;} ;
int
main (int argc, char *argv[])
{
    Mac48Address a;
    struct record r;
    std::map < Mac48Address , struct record > map ;
    map.insert(std::make_pair(a,r));
}

Sheena

unread,
Jun 23, 2013, 5:54:06 AM6/23/13
to ns-3-...@googlegroups.com
Actually I am doing these changes in Sta-wifi-mac.cc .I have made all the changes in Receive().Still I am getting the error
error: template argument for ‘template<class _T1, class _T2> struct std::pair’ uses local type ‘ns3::StaWifiMac::Receive(ns3::Ptr<ns3::Packet>, const ns3::WifiMacHeader*)::record’
Any suggestions?
Thanks

Junling Bu

unread,
Jun 23, 2013, 9:23:19 AM6/23/13
to ns-3-...@googlegroups.com
Hi,
if you put "struct record {double r;} ;" in main method as below:


int
main (int argc, char *argv[])
{
   struct record {double r;} ;

    Mac48Address a;
    struct record r;
    std::map < Mac48Address *, struct record > map ;
    map.insert(std::make_pair(&a,
r));
}
then compiling error : ‘template<class _T1, class _T2> struct std::pair’uses local type ‘main(int, char**)::record’
which is very similar to your error.
So my suggestion is put "struct record {double r;} ;"  outside of the method.
please have a try.


Reply all
Reply to author
Forward
0 new messages