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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:33:07+00:00 2026-06-14T13:33:07+00:00

I have the following class: class list { private: struct node { node() {

  • 0

I have the following class:

 class list {
      private:
        struct node {
          node() { data=T(); prev=next=this; }
          ˜node() {}
          T data;
          node *prev;
          node *next;
        };
      public:
        class iterator {
        public:
          iterator() : p(NULL) {}
          T & operator*() { return p->data; }
          iterator & operator++()
            { p = p->next; return *this; }
          iterator & operator++(int)
            { iterator tmp = *this; ++*this; return *tmp; }
          bool operator==(const iterator & rhs) const
            { return p == rhs.p; }
          bool operator!=(const iterator & rhs) const
            { return p != rhs.p; }
        private:
          friend class list<T>;
          iterator(node *p) : p(p) {}
          node *p;
        };
        iterator begin() { return iterator(head->next); }
        iterator end() { return iterator(head); }
        list();
        ˜list();
        etc ...
      private:
        int N;
        node *head;
        node *findnode(int);
    };

I see that the begin() function returns a constructor for the iterator class. Does this mean that a new iterator is created when it is called? If so, will the memory be recycled after the variable that this iterator is assigned to goes out of scope? I’m slightly confused, for the iterator constructor has no return type. If someone could shed some light on my issues, I would be most appreciative.

  • 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-14T13:33:08+00:00Added an answer on June 14, 2026 at 1:33 pm

    Yes a new iterator is created when begin is called. At a high level, yes the memory the iterator occupies will be recycled after it goes out of scope.

    Constructors do not have return types as they are called in place on the memory they are to initialize.

    At a somewhat lower level, variables that are declared on the stack have their destructor called when they go out of scope, which is one aspect of “recycling”. The memory they occupy is on the stack rather than in the heap (as it would be if new were called), so it doesn’t get freed in the sense of doing a delete or garbage collection. Rather the memory the variable had occupied may sit idle for a while or be immediately overwritten depending on if stack frames are being removed or added immediately after it goes out of scope (i.e the functions are returning up the stack or new calls are being made).

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

Sidebar

Related Questions

I have The Following Structure public class GraphData { private List<RecordPerDay> recordPerDay; public List<RecordPerDay>
I have the following class class X { private List<Calendar> calendars; // public int
Suppose I have the following class: public class Foo { private List<Integer> list =
I have the following class public class Element { public List<int> Ints { get;private
Say I have the following Hibernate-mapped class: public class ClassA { @OneToMany(fetch=EAGER) private List<ClassB>
I have the following class [DataContract] public class A { private List<B> b= new
I have the following class structure class Top : NotifyPropertyChanged { private List<Inner> innerList;
I have the following class: public class LooklessControl : Control { public List<int> IntList
I have the following ViewModel public class RecommendationModel { public List<CheckBoxItem> CheckBoxList { get;
Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string

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.