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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:52:29+00:00 2026-05-14T06:52:29+00:00

This is a bit of an involved problem, so I’ll do the best I

  • 0

This is a bit of an involved problem, so I’ll do the best I can to explain what’s going on. If I miss something, please tell me so I can clarify.

We have a callback system where on one side a module or application provides a “Service” and clients can perform actions with this Service (A very rudimentary IPC, basically). For future reference let’s say we have some definitions like so:

typedef int (*callback)(void*); // This is NOT in our code, but makes explaining easier.

installCallback(string serviceName, callback cb); // Really handled by a proper management system

sendMessage(string serviceName, void* arg); // arg = value to pass to callback

This works fine for basic types such as structs or builtins.

We have an MI structure a bit like this:

Device <- Disk <- MyDiskProvider

class Disk : public virtual Device
class MyDiskProvider : public Disk

The provider may be anything from a hardware driver to a bit of glue that handles disk images. The point is that classes inherit Disk.

We have a “service” which is to be notified of all new Disks in the system, and this is where things unravel:

void diskHandler(void *p)
{
    Disk *pDisk = reinterpret_cast<Disk*>(p); // Uh oh!

    // Remainder is not important
}

SomeDiskProvider::initialise()
{
    // Probe hardware, whatever...

    // Tell the disk system we're here!
    sendMessage("disk-handler", reinterpret_cast<void*>(this)); // Uh oh!
}

The problem is, SomeDiskProvider inherits Disk, but the callback handler can’t receive that type (as the callback function pointer must be generic).

Could RTTI and templates help here?

Any suggestions would be greatly appreciated.

  • 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-14T06:52:29+00:00Added an answer on May 14, 2026 at 6:52 am

    While I am not 100% sure I think static_cast from T* to void* and back to the original pointer type T* should work. As I see it the problem is that reinterpret_cast only changes the type of pointer without altering its actual value and static_cast in case of inheritance should adjust a pointer so that it points to the beginning of the object.

    DISCLAIMER: You are on the dark side of the language here and I cannot guarantee it will work at all.

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

Sidebar

Related Questions

I have this bit of JavaScript... 15 $('.ajax_edit_address').each(function() { 16 $(this).ajaxForm({ 17 target: $(this).parents('table.address').find('tr.address_header').children(':first'),
I'm working on something that involved using the Bit.ly API, and allow the user
This bit of code is taking almost a half second to execute. Could somebody
This bit of code comes with new classes that are subclasses of UITableViewController... -
To this bit of code I pass the string kellogs special k and I
IS this bit of code in PHP/mysql considered a stored procedure? $sql = 'SELECT
Consider this bit of obfuscated code. The intention is to create a new object
How do I change this bit of code so that I only allow pdf
I've got this bit of JQUERY: <script> function initNav() { $('.nav tr table td
What does this bit of code represent? I know it's some kind of if

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.