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
Post a Comment