* Mike Copeland:
> How do I work with a std::list that might have multiple objects
> having the same "key", but which have other data that is different?
> Here's code that compiles, but doesn't do quite what I expect:
> (Please note that there's some specialized I/o code here, but the
> logic flow should be clear...)
>
>>
> } gWork;
This is wrong. Don't use global variables.
> typedef list<GenCheck> NAMES;
> NAMES genData;
> list<GenCheck>::iterator gIter;
This is wrong. Don't use global variables.
> void nameGenderFile() // maintain NAMECHK.DAT file
> {
> int ii, jj = 0, kk = 0, mCt = 0, fCt = 0, uCt = 0;
> char gCode;
This is wrong. Don't use misleading prefixes (here "gCode").
> Str24 sName, fName, lName, priorName = "";
This is wrong. You haven't defined Str24. Anyway, use std::string.
> strcpy(f3, "myfile.hst"), fv3.openFile("", f3, "", "rt");
This is wrong. You haven't defined f3 or fv3. Anyway, use std::string.
> gWork.genCode = gCode, gWork.useCount = 1;
This is wrong. Because I don't remember which of "," and "=" has
higher precedence. Therefore, in all likelyhood neither do you.
> What have I done wrong here? Please advise. TIA
See above for some examples. :-)
It's not directly reason why your code doesn't work. It's the reason
for the reason that your code doesn't work. Namely, choosing complex
ways to do things.
General principle: keep it simple. E.g., avoid global variables,
avoid reliance on obscure operator precedence, avoid using char arrays
instead of std::string, and so on. When you have rewritten the code
with this in mind, so that it's simple enough to understand, chances
are that it will then work.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


|