how to populate map in header file in C++ -


how populate map in header file? have map<int,int>sample needs populated in header file. right populating in .cpp file in local function want move code in header file.

how populate map in header file?

you can initializing other variable.

i have map<int,int>sample needs populated in header file.

that not sound requirement. perhaps there flaw in design. try provide access global data through function. can convert to:

map<int,int>& getsample(); 

in header file. can implement in .cpp file way wish to. e.g.

map<int,int>& getsample() {         static map<int,int> sample = constructsample(); // assuming can create such function.    return sample; } 

that right populating in .cpp file in local function want move code in header file.

that not sound idea. don't if can avoid it.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -