470,848 Members | 1,763 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

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,

May 26 '06 #1
1 2349
utab wrote:
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.

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
May 26 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Scott J. McCaughrin | last post: by
15 posts views Thread by Samee Zahur | last post: by
3 posts views Thread by Jay | last post: by
12 posts views Thread by Joe Narissi | last post: by
14 posts views Thread by Jess | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.