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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:40:30+00:00 2026-05-14T14:40:30+00:00

I have a function which creates an array of Maps: map<string, int> *pMap And

  • 0

I have a function which creates an array of Maps:

map<string, int> *pMap

And a function which writes maps to the array:

int iAddMap(map<string, int> mapToAdd, map<string, int> *m, int i)
{
    m = &(pMap[i]);
    memcpy(m, mapToAdd, sizeof(map<string, int>));
}

And a function to get maps from the array

map<string, int>& getMap(int i)
{
    return pMap[i];
}

I can write maps to the array without any issue, but every get call results in a seg fault:

int val; 
// val defined after this
map<string, int> * pGetMap = &(getMap(val));

Any suggestions on why this is happening?

  • 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-14T14:40:31+00:00Added an answer on May 14, 2026 at 2:40 pm

    You cannot use memcpy() to copy objects like maps, or indeed any other kind of C++ container – you need to use assignment, which takes into account the map’s underlying structure and se,mantics. And you should be using a vector <map>, as you actually seem to want a copy rather than a pointer.

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

Sidebar

Ask A Question

Stats

  • Questions 540k
  • Answers 540k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The default MVC application will store user credentials in aspnetdb.mdf… May 17, 2026 at 2:35 am
  • Editorial Team
    Editorial Team added an answer You want getpwnam. Here's a complete example I just wrote:… May 17, 2026 at 2:35 am
  • Editorial Team
    Editorial Team added an answer No, you cannot do that without writing FiddlerScript to extend… May 17, 2026 at 2:35 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a function which creates an array of pointers. The function which allocates
I am trying to create a function which maps a recurring pattern of integers
I have the following code which uses an array to write the result to
I created a class Foo that has the method toArray() that returns an Array<Int>
Problem I have a API V3 map, with a content window for each marker.
I am having some trouble with the Google Maps API . I have an
I've created a simple function which allows me to determine which status options a
I have my own hand-rolled PHP MVC framework for some projects that I'm working
I have a bit of a problem. I am trying to do the following
I'd need a class like std::auto_ptr for an array of unsigned char*, allocated with

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.