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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:45:34+00:00 2026-05-15T18:45:34+00:00

I’m having a problem with a couple of event handler classes I’m trying to

  • 0

I’m having a problem with a couple of event handler classes I’m trying to write. Basically, the idea is to have an event handler class for each logical group of objects. In most cases, the events are between objects and their handler, but in some cases events are also sent between handler objects as well.

I’ve written the code such that the events are placed on a stack (stack as in user created structure; the events themselves are allocated using new) and deleted after their information is read and acted upon. This is giving me some problems because in one case, the event is sent along a chain of three handlers. Say, HandlerA sends a new Event to HandlerB, which places it on the stack and reads it, sending it to HandlerC, which reads it and performs whatever it needs to perform, after which it deletes the Event pointer and sets it to NULL. Now, we pop back to HandlerB and, well, it also wants to delete and NULL the pointer to the event. But the pointer is a local variable, and it ends up deleting the same address twice, giving an exception.

How do you go around this? Do you need to use one of those fancy auto_ptrs (still an early learner here), or am I missing something fundamental here?

  • 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-15T18:45:35+00:00Added an answer on May 15, 2026 at 6:45 pm

    I’ve written the code such that the events are placed on a stack and deleted after their information is read and acted upon.

    There is some confusion here – objects on the stack should not be deleted. Objects created with new (on the heap) should.

    In general, you should define a clear ownership strategy for your objects on the heap. Each object should have one owner, and it should be clear who the owner is at any point in time. That owner – and it alone – shall delete the object.

    You may also want to use boost::shared_ptr (it may be available also as std::tr1::shared_ptr, depending on your compiler) instead of raw pointers. This keeps count of the references to the object, and deletes it when the ref count drops to 0.

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

Sidebar

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.