Connecting Tech Pros Worldwide Help | Site Map

Static Map

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 26th, 2006, 01:25 AM
utab
Guest
 
Posts: n/a
Default Static Map

Dear all,

In the private data section of my class I have defined a

static map<string, map<string,int> > Ent_fname_fid;

and in the implementation file I wanted to initialize it like a
built-in static variable
(if I gave a static int a in the class then I would have to write int
Classname::a=0)

This is not possible with the below code

map<string, map<string,int> > classname::Ent_fname_fid;

Ent_fname_fid["GRID"].insert(make_pair("GRID",1));
Ent_fname_fid["GRID"].insert(make_pair("ID",2));
Ent_fname_fid["GRID"].insert(make_pair("CP",3));
Ent_fname_fid["GRID"].insert(make_pair("X1",4));
Ent_fname_fid["GRID"].insert(make_pair("X2",5));
Ent_fname_fid["GRID"].insert(make_pair("X3",6));
Ent_fname_fid["GRID"].insert(make_pair("CD",7));
Ent_fname_fid["GRID"].insert(make_pair("PS",8));
Ent_fname_fid["GRID"].insert(make_pair("SEID",9));

This code is not in a function just outside all function definitions.

Regards,


  #2  
Old May 26th, 2006, 01:35 AM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: Static Map

utab wrote:[color=blue]
> In the private data section of my class I have defined a
>
> static map<string, map<string,int> > Ent_fname_fid;
>
> and in the implementation file I wanted to initialize it like a
> built-in static variable
> (if I gave a static int a in the class then I would have to write int
> Classname::a=0)
>
> This is not possible with the below code
>
> map<string, map<string,int> > classname::Ent_fname_fid;
>
> Ent_fname_fid["GRID"].insert(make_pair("GRID",1));
> Ent_fname_fid["GRID"].insert(make_pair("ID",2));
> Ent_fname_fid["GRID"].insert(make_pair("CP",3));
> Ent_fname_fid["GRID"].insert(make_pair("X1",4));
> Ent_fname_fid["GRID"].insert(make_pair("X2",5));
> Ent_fname_fid["GRID"].insert(make_pair("X3",6));
> Ent_fname_fid["GRID"].insert(make_pair("CD",7));
> Ent_fname_fid["GRID"].insert(make_pair("PS",8));
> Ent_fname_fid["GRID"].insert(make_pair("SEID",9));
>
> This code is not in a function just outside all function definitions.[/color]


Correct. This is not possible. So, put it in a function and init
a dummy int variable with that function:

int dummy = function_to_fill_the_map(Ent_fname_fid);

The function should take one argument - a reference to non-const
map of yours. In the body of the function you will put all those
'insert' things. Return 0 from the function.

V
--
Please remove capital As from my address when replying by mail


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.