-
December 16th, 2008, 04:22 AM
#1
Struct
typedef struct
{
list<int> lc;
} x;
for( li = x.lc.begin(); li != x.lc.end(); li++ )
{
}
gives the error below:
expected primary-expression before '.' token
Any ideas?
-
December 16th, 2008, 04:26 AM
#2
Re: Struct
x is a type, not an object. That's what the "typedef" means.
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
December 16th, 2008, 04:46 AM
#3
Re: Struct
Thanks Graham.
what if I do this?
typedef struct
{
int i;
int j;
int k[4];
} x;
x obj;
list<obj> lc; // STL
how do I put values in my elements and access each element using an iterator? I'm thinking to start,
lc.push_back(???) // for each element?
list<obj>::iterator li;
for( li = lc.begin(); li != lc.end(); li++ )
{
??
}
-
December 16th, 2008, 06:34 AM
#4
Re: Struct
Code:
x obj;
list<x> lc; // STL
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
December 16th, 2008, 01:48 PM
#5
Re: Struct
now how do I access individual elements?
-
December 16th, 2008, 01:52 PM
#6
Re: Struct
You seem to have that down already with the for loop and the iterator.....
-
December 17th, 2008, 01:47 AM
#7
Re: Struct
Originally Posted by mikeleblanc666
now how do I access individual elements?
http://www.cppreference.com/wiki/stl/list/start
Please use code tags.
Before post, make an effort yourself, try googling or search here.
When posting, give a proper description of your problem, include code* and error messages.
*All code should include code tags
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|