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

  • Home
  • SEARCH
  • 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 8813931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:59:02+00:00 2026-06-14T03:59:02+00:00

When iterating over an vector (or other container) of pointers, is there any difference

  • 0

When iterating over an vector (or other container) of pointers, is there any difference between and/or over advantage using:

for (it = v.begin(); it != v.end(); ++it) {
    (*it)->method();
}

or

for (it = v.begin(); it != v.end(); ++it) {
    (**it).method();
}
  • 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-06-14T03:59:03+00:00Added an answer on June 14, 2026 at 3:59 am

    In the C language, there is no difference. However, in C++, the -> operator can be overloaded, whereas the member selection . operator cannot.

    So in (*foo)->bar *foo could designate a class object which acts as a smart pointer, though this won’t happen if foo is an iterator over a standard C++ container of pointers, which means that *foo evaluates to a pointer.

    And in (**foo).bar, **foo has to be a class object with a member called bar (which is accessible).

    The unary * can also be overloaded (which is how the iterator foo, a class object, returns the object which it references).

    In other words, the expressions can diverge in meaning, but if *foo is a pointer to a class/struct, then the equivalence inherited from the C language applies: (*ptr).member is equivalent to ptr->member.

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

Sidebar

Related Questions

Iterating over a vector works: std::vector<int> collection = {2, 3, 4, 5435345, 2}; std::for_each(collection.begin(),
I am iterating over an STL vector and reading values from it. There is
I have a class (foo) that contains a vector. If i try iterating over
When iterating over a standard container, do you think it's a good idea to
Is there a better shorter way than iterating over the array? int[] arr =
Context When iterating over a set of Rdata files (each containing a character vector
Say you're iterating over a list using a nested for loop like this: for(
I'm iterating over a vector, for each element I look something up in a
When iterating over std::map<X,std::vector<Y> > , may I sort the vectors, or might that
When iterating over elements of a vector it is preferred to use iterators instead

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.