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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:00:51+00:00 2026-06-05T15:00:51+00:00

Here’s a relatively small but segfaulting project. I’ve searched quite a few posts doing

  • 0

Here’s a relatively small but segfaulting project. I’ve searched quite a few posts doing similar things and while many seemed to be having the same problem, none solved my problem.

The basic issue is this: I have an object (myGraph) with a member vector, and a few methods. A method inside another class invokes one of myGraph‘s methods, which in turn invokes another one. Inside that function, a push is made to a vector of ints in myGraph. However, this push results in a segfault.

In a somewhat extreme measure, I’ve been commenting out large portions of code (on a fresh branch of course) and have reduced my code down to a sparse few items. (other posts seemed to indicate that this kind of thing might be caused by bad code elsewhere) yet I am still getting a segfault.

What follow are the watered-down files, composed of the few things remaining uncommented. I say “watered-down” because a lot of declarations (of now-empty functions and such) have been removed. If you need additional information (for instance, if it’s important – somehow – that I’m using a virtual function somewhere… as a radical example) just let me know.

in Dispatcher.h:

class myGraph;

class CDispatcher
{
public:
    CDispatcher(void);
    ~CDispatcher(void);

    void ProcessCall(string buf);

    myGraph* mymap;

};

in Dispatcher.cpp:

void CDispatcher::ProcessCall(string buf) 
{
    mymap->getDistance(0,1);
};

in mygraph.cpp:

int myGraph::getDistance(int start, int end) {
    Dijkstras(start,end);

    // This is just to return something
    return 5;
};

vector<int> myGraph::Dijkstras(int startVert,int endVert) {

    vertices_i.push_back(2); // This line results in a segfault
    cout << "push successful" << endl;

    // This is just to return something
    vector<int> unvisited;
    return unvisited;
};

mygraph.h:

typedef struct edge
{
    int endVert;
    int weight;
} edge;


typedef struct vertex
{
    long dist;
    bool visited;
    int prev;

    vector<edge> edges;
} vertex;
class myGraph
{
public:
    myGraph(int initSize);
    ~myGraph(void);

    int getDistance(int start, int end);
    vector<int> Dijkstras(int startVert,int endVert);

    //vector<vertex> vertices; // The original vector that was segfaulting
    vector<int> vertices_i; // Simpler vector, of just ints. Still segfaults

};
  • 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-05T15:00:52+00:00Added an answer on June 5, 2026 at 3:00 pm

    The unavoidable conclusion is that the member pointer myGraph* mymap is pointing to garbage; you’ve apparently neglected to initialize it to point to a myGraph object. You need to create an object for it to refer to in the CDispatcher constructor — i.e.,

    CDispatcher(void) : mymap(new myGraph(1)) {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is what I am currently doing. PHP echo's out the recent post in
here is my php code $titikPetaInti = array(); while($row = mysql_fetch_assoc($hasil2)) { $titikPetaInti[] =
Here's what I'm doing. I want to upload multipart file via Ajax to my
Here's what I'm trying to do... It's quite simple and obviously there must be
Here is my code: echo '<table class=class1><tbody>'; while ($row1=mysql_fetch_array($result1)){ echo '<tr><td>'.$row1['firstname'].'</td><td>'.$row1['lastname'].'</td></tr>'; } echo '</tbody></table>';
Here's a very simple repro: Start up VS2010 or VS2008, new a WPF project
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the code in a function I'm trying to revise. This example works
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`

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.