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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:36:30+00:00 2026-05-20T21:36:30+00:00

I am working on an object that contains an array of queues with an

  • 0

I am working on an object that contains an array of queues with an array length that isn’t decided until the constructor is called. Basically it looks something like the following

#include <queue>

class myClass{
public:
  //public functions
private:
  //private functions and variables

  queue<int>* myQueue;
};

it is initialized like so:

myClass::myClass(int numOfQueues){
  myQueue = new queue<int>[numOfQueues];
}

This all works beautifully, it seems. it functions exactly like I was hoping it would, but now every time I exit the program I get a segmentation fault. The class has some other arrays in it that are initialized in the same way, but those are of types bool and int instead of queue. My destructor looks like:

myClass::~myClass(){
  delete boolArray;
  delete intArray;
  delete myQueue;
}

Now I assume this destructor is working for the boolArray and intArray pointers, because I didn’t start to get a segfault until I added myQueue. Does anyone have any idea what the proper way is to write the destructor? Is it possible that this is all I have to do and the destructor just isn’t being called at the proper time?

  • 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-20T21:36:30+00:00Added an answer on May 20, 2026 at 9:36 pm

    Because you allocated using new[] you should do delete[] myQueue; in destructor. Otherwise it would invoke undefined behavior. BTW, you can use std::vector<std::queue<int> > if you don’t want to get this type of memory management issues.

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

Sidebar

Related Questions

I am working on a Javascript object that contains some YUI objects. The key
I am working on an xts object that contains some 0s in one of
I'm working with 6 csv files that each contain the attributes of an object.
I have a basic XML object that I'm working with. I can't figure out
I'm working with SOAP using the javax.xml.soap package. I have a javax.xml.soap.SOAPMessage object that
i have created an IE band object (toolbar) that is working well. however, when
I'm working on a small roguelike game, and for any object/thing that is not
I have a Graphics object of JPanel and that is working fine: import java.awt.Color;
After working with the .NET GDI+ Rectangle object, I've noticed that if I create
I'm working on a homework project that requires me to create an object from

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.