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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:32:09+00:00 2026-05-31T10:32:09+00:00

Say I have an array of void pointer pointing to objects of different types

  • 0

Say I have an array of void pointer pointing to objects of different types and I want to pass them through a function and cast them to pointers of their respective type, how would I go about doing this? I’ve tried this current code, but I get error:

‘void*’ is not a pointer-to-object type

objectA myObjectA;
objectB myObjectB;
objectC myObjectC;
objectD myObjectD;

void *data[4];

data[0] = static_cast<void *>( &myObjectA );
data[1] = static_cast<void *>( &myObjectB );
data[2] = static_cast<void *>( &myObjectC );
data[3] = static_cast<void *>( &myObjectD );

void dereference( void *data )
{
    objectA *objA_ptr = static_cast<objectA *>( data[0] );
    objectB *objB_ptr = static_cast<objectB *>( data[1] );
    objectC *objC_ptr = static_cast<objectC *>( data[2] );
    objectD *objD_ptr = static_cast<objectD *>( data[3] ); 
}

Anyone know the correct way to implement this?

edit: For context, I’m using opencv and trying to create a simple gui interface with a trackbar. Opencv allows for userdata to be fed into the TrackbarCallback which is called when the slider is moved, but only in the form of a void pointer.

 int createTrackbar( const string& trackbarname, const string& winname,
                           int* value, int count,
                           TrackbarCallback onChange=0,
                           void* userdata=0); 
  • 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-31T10:32:10+00:00Added an answer on May 31, 2026 at 10:32 am

    Say I have an array of void pointer

    void deference( void *data )
    

    That’s not an array of void pointers, it’s a single void pointer.

    Change that to void **, and then since you’re mixing C and C++ styles up anyway, why not just use a C style cast? :

    objectA *objA_ptr = (objectA *) data[0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a function that receives a byte array: void fcn(byte* data) {
Say I have an array of table DDL queries and I want to get
Say I have an array of arbitrary size holding single characters. I want to
Let say I have a multi-dimensional array like int a[10][10] int b[10][10] void arrayCopy(int*
I have a basic question on array and pointer in C/C++. Say I have:
Say I have NSMutableArray *array1 with 10 objects. I want to create an *array2
I have quite peculiar problem. I want initialize an array pointed by a void
As an example, say I have an array of names and I want to
Suppose we have an array say: int arr[1000]; and I have a function that
Let's say I have array of bytes: byte[] arr = new byte[] { 0,

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.