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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:08:36+00:00 2026-06-14T00:08:36+00:00

I am currently working in C++ and I face this challenge. Here is a

  • 0

I am currently working in C++ and I face this challenge. Here is a code of my class in the header file:

class PID
{
   private:
   int PID;
   int total;

   public:
   PID(); // Constructor
   int returnPID(); // Returns PID.
};

Here is the code declaration in cpp file:

PID::PID()
{
    PID=INT_MAX;
    total=0;
}

int PID::returnPID()
{
    return PID;
}

And here is the declaration and the initialization in main of a table contaning pointers to objects of the class PID:

PID* table[1000000];

for (int i=0; i<1000000; i++)
{
    table[i]=new PID;
}

So I suppose this uses the constructor I have created above to set the PID to MAX_INT. When I try to access the content of table[i].PID using returnPID within the initialization for everything works great, something like this:

for (int i=0; i<1000000; i++)
{
    table[i]=new PID;
    int display=table[i]->returnPID();
    cout<<display<<endl;
}

The problem occurs when I am trying to access table[i] contents outside and after the initialization for. My main crashes and it returns a number (-1073741571) as an error. It seems like not even one command from the main is executed. Here is a sample of the code that seems to reproduce the problem:

for (int i=0; i<1000000; i++)
{
    table[i]=new PID;
}
for (int i=0; i<1000000; i++)
{
    int display=table[i]->returnPID();
    cout<<display<<endl;
}

I have been working on this for more than two hours without coming to any solution and it just doesn’t seem logical. Anyone have any explanation for this?

EDIT: Any table with less than 1.000.000 spots will work correctly. Maybe it has something to do with this although I still don’t see the connection.

  • 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-14T00:08:37+00:00Added an answer on June 14, 2026 at 12:08 am

    Anyone have any explanation for this?

    It seems like you’re running out of stack space.

    Can your compiler handle a million integers, instead of a million PID*?

    Any table with less than 1.000.000 spots will work correctly. Maybe it
    has something to do with this although I still don’t see the
    connection.

    It has everything to do with that.

    I tried this:

    int main(){
        int bec[10000000];
        for (int i=0; i<10000000;i++){
            bec[i] = i;
        }
        printf("%d\n",rand()%1000);
        return 0;
    
    }
    

    It segfaults for the same reason as yours.

    The only way to solve this problem is to use less stack space. You can declare bec outside of main and not use stack space for that or you can use std::vector. You have plenty of options.

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

Sidebar

Related Questions

i'm working on a website and currently using the @font-face tehnique ( this +
appreciate any help with this. We are currently working on remodelling a legacy project
please read all of this before commenting. I'm currently working on a large website
I'm currently working on my online portfolio . As you can see, @font-face runs
Currently working with converting SQLException error messages into messages that are more useful for
Currently working with the following package structure: /package __init__.py final.py /write __init__.py write.py /data
Currently working for the first time with JSON and with little experience of jQuery.
Currently working in the deployment of an OFBiz based ERP, we've come to the
Currently working on a VBScript to automate some of the dirty PST ingestion work
Currently working on a site built in Django and i'm getting an issue when

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.