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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:14:48+00:00 2026-06-07T09:14:48+00:00

I had to implement a circular queue for class. The program properly Enqueues and

  • 0

I had to implement a circular queue for class. The program properly Enqueues and Dequeues when I test it. But whenever I create a new object and set it equal to another, everything prints out correctly, but it crashes at the end, with an error:

Expression: _BLOCK_TYPE_IS_VALID(pHead -> nBlockUse)

I ran the debugger and it says the problem is in a line in the Dequeue function. Here is That function.

void CQUEUE::Dequeue()
{
if(Isempty())
{
    cout << "Queue is  empty, nothing to delete." << endl;
    return;
}

if((!Isempty()) && (front == back)) //When there is only 1 item in the queue
{                                   // front and back will point to the same node
    delete front;                   //but it wont be null because of that 1 item
    front = back = 0;   
    return;
}

qnode *p = front;
front = front -> next;
delete p;//<----------DEBUGGER POINTS HERE**************
front -> prev = back;
return;

}

Like I said, the program works fine until I create a new object and do this

 CQUEUE j = k;//Any Enqueues and Dequeues after this work, but it crashes

Here is the copy constructor incase that is the problem?

CQUEUE::CQUEUE(CQUEUE & original)//Will not compile if I put Const 
{                               //in the parameter for some reason
front = back = 0;           //So I took it out
(*this) = original;
front -> prev = back;
back -> next = front;

}
  • 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-07T09:14:49+00:00Added an answer on June 7, 2026 at 9:14 am

    In your copy constructor you do the following:

    (*this) = original;
    

    The means that your front pointers in CQUEUE j and CQUEUE k both point to the same memory.

    When void CQUEUE::Dequeue() is called for both j and k, delete p; double deletes the memory, resulting in a crash.

    Also, your copy constructor must be declared as const. CQUEUE::CQUEUE(const CQUEUE& original). Without more code is hard to say, but in your copy constructor you need to make deep copies of the pointers (allocate memory using new). Reading What is The Rule of Three? might help.

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

Sidebar

Related Questions

I had try to implement the send me log feature into my apps but
I am trying to implement a image recognition program in C++ . I had
I have implemented mail composer. But it opens mail composer whenever user had implemented
I had to implement a C function in an Objective-C class that normally would
I had asked a question on how to implement real time updates in ASP.NET
If I had a Java generic class of... public class EntityStuff<C> extends AbstractPropertyStuff<C> implements
I want to implement the Augmented Reality with layer Example like this:-http://www.youtube.com/watch?v=b64_16K2e08 i had
For an assignment, we had to implement something like a very basic sexp parser,
For one of my recent projects, I had to implement field change tracking .
I had implement the project that have to use QR Reader via Zxing Project.

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.