CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Struct

  1. #1
    Join Date
    Dec 2008
    Posts
    4

    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?

  2. #2
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    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


  3. #3
    Join Date
    Dec 2008
    Posts
    4

    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++ )
    {
    ??
    }

  4. #4
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    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

  5. #5
    Join Date
    Dec 2008
    Posts
    4

    Re: Struct

    now how do I access individual elements?

  6. #6
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Struct

    You seem to have that down already with the for loop and the iterator.....

  7. #7
    Join Date
    Jan 2003
    Posts
    615

    Re: Struct

    Quote Originally Posted by mikeleblanc666 View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured