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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:57:06+00:00 2026-05-22T15:57:06+00:00

I have a problem with the STL list class . I have a base

  • 0

I have a problem with the STL list class. I have a base class called Contact, and three derived classes, Friend, Colleague and Acquaintance. Each instance of the derived classes has certain fields which I modify in the fill*Class*Details() function. The problem is that when it reaches the push_back line, my program gives me an error saying list insert iterator outside range. What can that be from?

void Agenda::pushContact(string line, string temp)//function that adds a contact of type temp, containing the fields from line to the list
{       
    Contact *c;

    if(temp=="friend") //the contact to add is of type friend
    {
        c = new Friend();
        fillFriendDetails(c,line);//the details of Friend c will be filled
    }
    else if(temp=="colleague")
    {
        c = new Colleague();
        fillColleagueDetails(c,line);//the details of Colleague c will be filled
    }
    else if(temp=="acquaintance")
    {
        c = new Acquaintance();
        fillAcquaintanceDetails(c,line);//the details of Acquaintance c will be filled
    }
    contactList.push_back(c);
}

Also, the contactList is defined as list <Contact*> contactList;.

Edit: This is how the Contact class (+derived classes) are defined:

class Contact
{
public:
    string getFullName() {  string fullName;fullName.append(firstName); fullName.append(" ");fullName.append(lastName); return fullName;}
public:
    void setFullName(string newFirstName, string newLastName) { firstName = newFirstName; lastName = newLastName;}
public:
    string getFirstName() { return firstName;}
public:
    void setFirstName(string newFirstName) {firstName = newFirstName;}
public:
    string getLastName(){return lastName;}
public:
    void setLastName(string newLastName){lastName = newLastName;}
public:
    string getPhoneNo(){return phoneNo;}
public:
    void setPhoneNo(string newPhoneNo) {phoneNo = newPhoneNo;}
public:
    void setType(string newType){type=newType;}
public:
    string getType(){return type;}
private:
    string firstName;
    string lastName;
    string phoneNo;
    string type;

//SubClass setters and getters
public:
    virtual void setDateOfBirth(string birth) {}
    virtual string getDateOfBirth() {return 0;}
    virtual void setCity (string newCity) {}
    virtual string getCity() {return 0;}
    virtual void setFaculty (string newFaculty) {}
    virtual string getFaculty() {return 0;}
    virtual void setGroup (string newGroup) {}
    virtual string getGroup() {return 0;}
    virtual void setJob (string newJob) {}
    virtual string getJob () {return 0;}


};


class Friend : public Contact
{
public:
    void setDateOfBirth(string birth)   {dateOfBirth=birth;}
public:
    string getDateOfBirth() {return dateOfBirth;}
public:
    void setCity (string newCity){city=newCity;}
public:
    string getCity(){return city;}

private:
    string dateOfBirth;
    string city;    //current city of residence
};

class Colleague : public Contact
{
public:
    void setFaculty (string newFaculty){faculty = newFaculty;}
public:
    string getFaculty(){return faculty;}
public:
    void setGroup (string newGroup){group = newGroup;}
public:
    string getGroup(){return group;}


private:
    string faculty;
    string group;
};

class Acquaintance : public Contact
{
public:
    void setJob (string newJob){job=newJob;}
public:
    string getJob (){return job;}

private:
    string job;

};
  • 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-22T15:57:07+00:00Added an answer on May 22, 2026 at 3:57 pm

    It looks like the list is being mismanaged at a different point in the code, because the error implies end is incorrect. Most likely either the list is deleted/out of scope or some incorrect erases were performed on the list elements (say using invalid iterators).

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

Sidebar

Related Questions

I am new to STL. I have written a Template Base class as follows
I have the following problem. Consider the classes class face { virtual std::vector<ptr>& get_vertices(void)
I enjoy developing algorithms using the STL, however, I have this recurring problem where
I have written a list-like template class sll (Single Linked List). Now, I am
STL containers have the problem that iterators can be invalidated when the container changes.
I'm working on a problem which requires me to use the STL linked list
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE

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.