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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:15:02+00:00 2026-05-25T15:15:02+00:00

I get the error in the title when I try to run my code…

  • 0

I get the error in the title when I try to run my code…
here’s what I’m running

class MyQueue {
    tile* queue;
    int size;
public:
    MyQueue(int cap);
    ~MyQueue();
    void enqueue(tile t);
    tile dequeue();
    bool isEmpty();
};

void MyQueue::enqueue(tile t) {
queue[size] = t;
size++;
}

tile MyQueue::dequeue() {
tile temp = queue[0];
tile* victim = queue;
queue++;
delete victim;
return temp;
}

bool MyQueue::isEmpty() {
if (size == 0)
    return true;
else
    return false;
}

MyQueue::MyQueue(int cap) {
queue = new tile[cap];
size = 0;
}

MyQueue::~MyQueue() {
delete[] queue;
}

int main(int argc, char *argv[]) {
tile tile1; tile1.type = '1';
tile tile2; tile2.type = '2';
tile tile3;

MyQueue q(10);
q.enqueue(tile1);
q.enqueue(tile2);
tile3 = q.dequeue();
cout<<tile3.type<<" =1?"<<endl;
return 0;
}

valgrind:

==4506== Mismatched free() / delete / delete []
==4506==    at 0x4C27FFF: operator delete(void*) (vg_replace_malloc.c:387)
==4506==    by 0x400CD2: MyQueue::dequeue() (MyQueue.h:37)
==4506==    by 0x400DD7: main (p1.cpp:24)
==4506==  Address 0x5964040 is 0 bytes inside a block of size 120 alloc'd
==4506==    at 0x4C28658: operator new[](unsigned long) (vg_replace_malloc.c:305)
==4506==    by 0x400D35: MyQueue::MyQueue(int) (MyQueue.h:49)
==4506==    by 0x400D9F: main (p1.cpp:21)
==4506== 
1 =1?
==4506== Invalid free() / delete / delete[]
==4506==    at 0x4C27C7B: operator delete[](void*) (vg_replace_malloc.c:409)
==4506==    by 0x400D74: MyQueue::~MyQueue() (MyQueue.h:54)
==4506==    by 0x400E2F: main (p1.cpp:21)
==4506==  Address 0x596404c is 12 bytes inside a block of size 120 free'd
==4506==    at 0x4C27FFF: operator delete(void*) (vg_replace_malloc.c:387)
==4506==    by 0x400CD2: MyQueue::dequeue() (MyQueue.h:37)
==4506==    by 0x400DD7: main (p1.cpp:24)
==4506== 
==4506== 
==4506== HEAP SUMMARY:
==4506==     in use at exit: 0 bytes in 0 blocks
==4506==   total heap usage: 1 allocs, 2 frees, 120 bytes allocated
==4506== 
==4506== All heap blocks were freed -- no leaks are possible
==4506== 
==4506== For counts of detected and suppressed errors, rerun with: -v
==4506== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 4 from 4)

seems like something stupid but I can’t figure it out for the life of me, thanks for the help

  • 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-25T15:15:03+00:00Added an answer on May 25, 2026 at 3:15 pm

    The problem might be due to the fact that in the constructor you’re dynamically allocating an array:

    queue = new tile[cap]; 
    

    but in deque you delete it using the non-array delete operator.

    tile* victim = queue;
    queue++;
    delete victim;  
    

    It just looks like the logic in the code is mismatched. On one hand there is code that allocates dynamic arrays but then in other places it deletes individual elements of that dynamically allocated array.

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

Sidebar

Related Questions

I get a 500 internal server error when I try to run the code
When I try to run this page (video.php), I get the following error: Parse
When I try to run this script i get error in IE: Unterminated string
I get this error when I run my code. This is a continuation from
Like the title says, the error I get is the following: An invalid '/'
In our application we've run into an error numerous times where we get error
I am using following PHP code for trigger creation but always get error, please
When we try to create a view within a funcion we get ERROR: there
If I set pre-compile script into binary code to true I get error saying
How do I unit test my code that has LTS Datacontext. I get error

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.