473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 2451
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
15
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
5
by: Mountain Bikn' Guy | last post by:
How would I do this? public sealed class UtilityClass { public static MyObject Object1;//see note below about importance of static object names in this class public static MyObject Object2;...
3
by: Jay | last post by:
Why are there static methods in C#. In C++ static was applied to data only (I believe) and it meant that the static piece of data was not a part of the object but only a part of the class (one...
9
by: Laban | last post by:
Hi, I find myself using static methods more than I probably should, so I am looking for some advice on a better approach. For example, I am writing an app that involves quite a bit of database...
12
by: Joe Narissi | last post by:
I know how to create and use static constructors, but is there a such thing as a static destructor? If not, then how do you deallocate memory intialized in the static constructor? Thanks in...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
1
by: Sandro Bosio | last post by:
Hello everybody, my first message on this forum. I tried to solve my issue by reading other similar posts, but I didn't succeed. And forgive me if this mail is so long. I'm trying to achieve the...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.