Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 399919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:53:36+00:00 2026-05-12T16:53:36+00:00

Yet again I find myself struggling with the C++ syntax. I’m trying to iterate

  • 0

Yet again I find myself struggling with the C++ syntax.

I’m trying to iterate over a list of generic objects. That is I have objects of a class
Event<Q>, crammed into a std::list<Event<Q> >.

So I’m trying to get an iterator over the list and intuitively thought that

std::list<Event<Q> >::iterator it;
for (it = events.begin(); it != events.end(); it++) { ... }

should solve the problem. However, i keep getting these errors:

..\calendar.h:48: error: expected `;' before "it"
..\calendar.h:49: error: `it' was not declared in this scope

Is there a reason for it being this difficult?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T16:53:37+00:00Added an answer on May 12, 2026 at 4:53 pm

    Sure this should work, but it sounds like you either have one or both of the following in action.

    • Have Q a template parameter or a type that somehow otherwise depend on it (typedef to it). Put a typename before std::list then, so that the compiler knows that ::iterator is a type and can proceed analysis properly (it could be a static value member). Knowing it is a type, the compiler can produce better diagnostics for template definitions, and you are required to tell whether it is a type using typename.
    • Have events a const list. Use const_iterator then.

    Update: The shown compile error surely indicates that the first point is true: Q directly or indirectly depends on a template parameter, and you have to put typename like so:

    typename std::list< Event<Q> >::iterator it;
    

    The compiler believes you that it is a non-type, and so it requires some operator or semicolon behind ::iterator (like, a multiplication). Put typename to make it know it names a type instead.

    Update: See the Template FAQ for similar template issues and solutions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.