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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:39:20+00:00 2026-06-16T00:39:20+00:00

Have a look at this snippet: #include <string> #include <iostream> #include <vector> using namespace

  • 0

Have a look at this snippet:

#include <string>
#include <iostream>
#include <vector>

using namespace std;

class base {
public:
  string foo;
  base() {};
  base(const base &orig) {
    this->foo = orig.foo;
  };
 ~base() {} ;
};

class derived : public base {
public:
  string bar;
  derived(const derived &orig) : base(orig) {
    this->bar = orig.bar;
  }
  derived() : base() {} ;
  ~derived() {};
};

void asd(derived d)
{
    // works fine
    cout << d.foo << d.bar << endl;
}

int main(void)
{
    vector<derived> v;

    derived bla;

    bla.foo = "Test ";
    bla.bar = "String ";

    v.push_back(bla);

    asd(bla);

    // Why the hell does v.end()->foo and v.end()->bar segfault?!
    cout << v.end()->foo;
    cout << v.end()->bar << endl;
}

Why do I get an segmentation fault? This is the console output
(compiled with g++ -o test test.cpp -g)

./test
Test String 
zsh: segmentation fault  ./test

The this pointer of the class derived v.end() does not point to the correct position…
But why?

  • 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-16T00:39:21+00:00Added an answer on June 16, 2026 at 12:39 am

    end() is not an iterator pointing to the last element. It points to one past the last element. Dereferencing end() is illegal.

    Use back() if you want the last element.

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

Sidebar

Related Questions

What is the purpose of the Source attribute? Have a look at this snippet:
Have a look to this code snippet:- CommonService objcommonService; NetworkCredential myCredentials = new NetworkCredential(144552,
I would be most grateful if people could have a look over this snippet
Have a look at the following code snippet... File1.h void somefunc(int); File1.c #include File1.h
Have a look at this code snippet struct S{ int i; int j;}; int
Please have a look at this snippet: import xlrd,spss from xlrd import open_workbook wb=open_workbook('C:/temp/testbook.xls')
Could anybody have a look at this snippet of code and and tell me
Have a look to this code snippet:- -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [webData setLength:
Have a look at this code snippet: int i = 10; int *pi =
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css

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.