[LIP] C++ : Initialization of a static member

Shantanu Kumar <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
Hi friends,

	In one C++ class, I have to use a static member with the following
declaration:

static const std::map<std::string, unsigned int>

	The member should also be initialized to certain data. Since C++
forbids in-line initialization of non-integer static const members, I
have to do it outside the class declaration. Even there, I cannot do it
in a simple manner because I have to use the following method repeatedly
for every tuple that I have to insert into the map:

std::map::insert (pair<std::string, unsigned integer>) 

	Hence, as a last resort I have to write a static (factory) method just
so that it can create/return the map object that the static const data
member is supposed to hold.

	I'd like to know how do others address this issue of initializing
non-trivial static data members in a C++ class; whether a smarter way
exists where I don't have to write a static method just for
initialization.


Regards,
Shantanu
-- 
In a world without walls and fences, who needs windows and gates?



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.