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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:22:12+00:00 2026-05-19T14:22:12+00:00

The folowing code is giving a segfault when reaching the insert statement: rna* annealer::anneal(rna

  • 0

The folowing code is giving a segfault when reaching the insert statement:

rna* annealer::anneal(rna strand1, rna strand2, const rna & opponent){

 std::vector<nukleotid*>::iterator sit2;
 std::vector<nukleotid*>::iterator eit2;
 std::vector<nukleotid*>::iterator eit;

 if(tryAnneal(strand1, strand2, opponent)) {
  eit = strand1.getStrand().end();
  sit2 = strand2.getStrand().begin();
  eit2 = strand2.getStrand().end();

         //here be segfault
  strand1.getStrand().insert(eit, sit2, eit2);
  strand1.isAnnealed = true;
  rna* str = &strand1;
  std::cout << *str << std::endl;
  return str;
 }


    //...

 return NULL;
}

rna contains a vector, which is returned by getStrand().

Its driving me crazy. I really cant understand why theres a segfault. A slightly different version of the code, in which in didnt declare new iterators, but was just passing strand1.getStrand().end(); (and the two other), to vector::insert() derictly threw a length_error which does not make any sense either, as my vectors are small (~10 elements).

can anyone see what am i doing wrong here?`

  • 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-19T14:22:13+00:00Added an answer on May 19, 2026 at 2:22 pm

    If getStrand() returns a vector by value, then sit2 and eit2 are iterators into different copies of the vector, and both copies are destroyed as soon as you obtain the iterators. You need either to return the vector by reference or save the copy of the vector and obtain iterators from that one copy instead.

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

Sidebar

Related Questions

The following code executes a simple insert command. If it is called 2,000 times
Why is the following code giving an exception? function SetText(index, text) { try {
Why is the following code giving segmentation fault? #include <stdio.h> #include <stdlib.h> int main()
Following code is giving compilation error in visual studio 2009. #include <iterator> #include <vector>
The following code is giving me a NullPointerException . The problem is on the
The following code is giving me a lot of trouble. To note, .hover changes
The following code is giving me an error: // GetDirectoryList() returns Dictionary<string, DirectoryInfo> Dictionary<string,
The following code is giving me the parsed date as Wed Jan 13 00:00:00
Can you tell me why the following code is giving me the following error
Ok so here is the full code it keeps giving me crap about pdf_add_bookmark

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.