Newsgroup: comp.lang.c++
Subject: Initializing std::map Objects
From: mrc2323@...
Date: Sun, 23 Jun 2013 10:57:39 -0700
I have the following structure and declarations, and I'm looking for
any simple way to initialize a set of default values.
struct TSINFO
{
string tsDescr; // T-Shirt name
string tsValue; // source T-Shirt value
char tsCode; // T-Shirt code (cShirt)
char tsGender; // T-Shirt gender version
int tsCount; // count of T-Shirts of this type
} extern tsWork;
typedef map<char, TSINFO> shirtLUMap;
shirtLUMap tsLUMap;
shirtLUMap::iterator tsluIter; // lookup iterator
That is, I wish to create, say, 5 objects with specific values and
store them into the map. For example,
tsWork.tsCode = 'S';
tsWork.tsGender = 'U';
tsWork.tsCount = 0;
tsWork.tsValue = "";
tsWork.tsDescr = "Small";
shirtLUMap['S'] = tsWork;
tsWork.tsCode = 'M';
tsWork.tsGender = 'U';
tsWork.tsCount = 0;
tsWork.tsValue = "";
tsWork.tsDescr = "Medium";
shirtLUMap['M'] = tsWork;
tsWork.tsCode = 'A';
tsWork.tsGender = 'F';
tsWork.tsCount = 0;
tsWork.tsValue = "";
tsWork.tsDescr = "Female X-Small";
shirtLUMap['A'] = tsWork;
[etc.]
Such code is tedious, and I'd like to learn some way to "shorthand"
the process of declaring certain default values. Using a non-default
constructor seems useful, but I don't know how I'd do it here... Please
advise.. TIA
Subject: Initializing std::map Objects
From: mrc2323@...
Date: Sun, 23 Jun 2013 10:57:39 -0700
I have the following structure and declarations, and I'm looking for
any simple way to initialize a set of default values.
struct TSINFO
{
string tsDescr; // T-Shirt name
string tsValue; // source T-Shirt value
char tsCode; // T-Shirt code (cShirt)
char tsGender; // T-Shirt gender version
int tsCount; // count of T-Shirts of this type
} extern tsWork;
typedef map<char, TSINFO> shirtLUMap;
shirtLUMap tsLUMap;
shirtLUMap::iterator tsluIter; // lookup iterator
That is, I wish to create, say, 5 objects with specific values and
store them into the map. For example,
tsWork.tsCode = 'S';
tsWork.tsGender = 'U';
tsWork.tsCount = 0;
tsWork.tsValue = "";
tsWork.tsDescr = "Small";
shirtLUMap['S'] = tsWork;
tsWork.tsCode = 'M';
tsWork.tsGender = 'U';
tsWork.tsCount = 0;
tsWork.tsValue = "";
tsWork.tsDescr = "Medium";
shirtLUMap['M'] = tsWork;
tsWork.tsCode = 'A';
tsWork.tsGender = 'F';
tsWork.tsCount = 0;
tsWork.tsValue = "";
tsWork.tsDescr = "Female X-Small";
shirtLUMap['A'] = tsWork;
[etc.]
Such code is tedious, and I'd like to learn some way to "shorthand"
the process of declaring certain default values. Using a non-default
constructor seems useful, but I don't know how I'd do it here... Please
advise.. TIA
via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?25182-Initializing-std-map-Objects&goto=newpost
View all the progranning help forums at:
http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums
No comments:
Post a Comment