Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: std::list D...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 5 Topic 45891 of 47035
Post > Topic >>

Re: std::list Duplicates with Different Data

by "Alf P. Steinbach" <alfps@[EMAIL PROTECTED] > May 13, 2008 at 07:04 AM

* 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?
 




 5 Posts in Topic:
std::list Duplicates with Different Data
mrc2323@[EMAIL PROTECTED]  2008-05-12 21:49:44 
Re: std::list Duplicates with Different Data
"Alf P. Steinbach&qu  2008-05-13 07:04:36 
Re: std::list Duplicates with Different Data
Jerry Coffin <jcoffin@  2008-05-13 15:16:50 
Re: std::list Duplicates with Different Data
mrc2323@[EMAIL PROTECTED]  2008-05-13 14:35:15 
Re: std::list Duplicates with Different Data
Jerry Coffin <jcoffin@  2008-05-13 18:21:36 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 3:41:34 CDT 2008.