M
Mike Copeland
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
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