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 6836473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:21:35+00:00 2026-05-26T23:21:35+00:00

I have a problem with assigning an unintialized to an initialized iterator. The following

  • 0

I have a problem with assigning an unintialized to an initialized iterator. The following code excerpt produces an access violation when built with Visual Studio 2010. In previous versions of Visual Studio the code should work.

#include <list>

int main() {
    std::list<int> list;
    std::list<int>::iterator it = list.begin();
    std::list<int>::iterator jt;
    it = jt; // crashes in VS 2010
}

Wouldn’t this be considered valid C++?

I need this code to implement a “cursor” class that either points nowhere or to a specific element in a list. What else could I use as a value for an uninitialized iterator if I don’t have a reference to my container yet?

  • 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-26T23:21:36+00:00Added an answer on May 26, 2026 at 11:21 pm
     it = jt; // crashes in VS 2010
    

    This invokes undefined behaviour (UB). According to the C++ Standard ,jt is a singular iterator which is not associated with any container, and results of most expressions are undefined for singular iterator.

    The section §24.1/5 from the C++ Standard (2003) reads (see the bold text specifically),

    Just as a regular pointer to an array
    guarantees that there is a pointer
    value pointing past the last element
    of the array, so for any iterator type
    there is an iterator value that points
    past the last element of a
    corresponding container. These values
    are called past-the-end values. Values
    of an iterator i for which the
    expression *i is defined are called
    dereferenceable. The library never
    assumes that past-the-end values are
    dereferenceable. Iterators can also
    have singular values that are not
    associated with any container.

    [Example: After the declaration of an
    uninitialized pointer x (as with int*
    x;), x must always be assumed to have
    a singular value of a pointer.]
    Results of most expressions are
    undefined for singular values;
    the
    only exception is an assignment of a
    non-singular value to an iterator that
    holds a singular value. In this case
    the singular value is overwritten the
    same way as any other value.
    Dereferenceable values are always
    nonsingular.

    If MSVS2010 crashes this, it is one of infinite possibilities of UB, for UB means anything could happen; the Standard doesn’t prescribe any behavior.

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

Sidebar

Related Questions

I'm writing an app in Visual Studio C++ and I have problem with assigning
I have a bit of a problem with my PHP code, I am assigning
I have this new problem. I have the following code in JSF 2.0 with
I have a problem when assigning functions to the click event of a button
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
Very new to JS here. When I write PHP I have no problem assigning
I have a problem with this code: Header: @interface ViewController : UIViewController { IBOutlet
Question closed (answer accepted) replaced by Delphi 7: Access violation - TByteDynArray problem )
I have a problem assigning a value to an entity that has a reference.

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.