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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:42:32+00:00 2026-06-14T06:42:32+00:00

I have a map<key_t, struct tr_n_t*> nodeTable and I’m trying to perform nodeTable[a] =

  • 0

I have a map<key_t, struct tr_n_t*> nodeTable and I’m trying to perform nodeTable[a] = someNode where a is of type typedef long key_t and someNode is of type o_t*.

I get a segmentation fault at the following point in the execution in stl_function.h:

  /// One of the @link comparison_functors comparison functors@endlink.
  template<typename _Tp>
    struct less : public binary_function<_Tp, _Tp, bool>
    {
      bool
      operator()(const _Tp& __x, const _Tp& __y) const
      { return __x < __y; }
    };

Source code:

#include <stdio.h>
#include <stdlib.h>
#include <map>

using namespace std;

typedef long key_t;

typedef struct tr_n_t {
    key_t key;
    map<key_t, struct tr_n_t *> nodeTable;
} o_t;

int main() {
    o_t *o = (o_t *) malloc(sizeof(o_t));
    o->nodeTable[1] = o;
    return 0;
}

Am I not using the map right?

  • 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-14T06:42:33+00:00Added an answer on June 14, 2026 at 6:42 am

    The problem is that because you initialize o using malloc, its memory is allocated but its constructor isn’t invoked.

    Change it to o_t *o = new o_t(); because using new instead of malloc will invoke the map’s constructor.

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

Sidebar

Related Questions

I have a struct with a std::map of pointers inside it. I'm trying to
I have a stl::map which key type is a custom struct. I want to
I have a Map that uses a Set for the key type, like this:
I have a MAP which is optionally of type std::map and optionally of type
I'm trying to map a collection (of type map) using a foreign key and
I have a file context.ml where a map is defined module CtxMap = Map.make(struct
I have map with key and value and my goal is to get list
I have a map with a struct as key, I have overloaded the <
I want to have a map that has a homogeneous key type but heterogeneous
I have a Map whose keys are of generic type Key<T> , and values

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.