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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:57:46+00:00 2026-06-11T16:57:46+00:00

Note that I’m 95% unfamiliar with pointers. So here’s my dilemma, I have a

  • 0

Note that I’m 95% unfamiliar with pointers.

So here’s my dilemma, I have a structure let’s call it foo

struct foo{
int a;
}

so let’s create an instance of foo

foo test;

Now I want to assign a void pointer to point to this

 void *ptest;
 ptest = &test;

This all works great, but when it comes to modifying the contents (ie int a within foo), I’m not sure how to approach this. I tried static_cast like this:

static_cast<foo*>(ptest).a=0; 

but that didn’t work either. Any help would be appreciated. Thanks

  • 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-11T16:57:47+00:00Added an answer on June 11, 2026 at 4:57 pm

    You’re casting it to a pointer, thus you need to dereference it using the * operator or use the -> operator.

    Option A:

    *(static_cast<foo*>(ptest)).a=0
    

    Option B:

    static_cast<foo*>(ptest)->a=0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please note that I have seen a similar query here , but think my
Note that I'm aware of other yield in vb.net questions here on SO. I'm
(Please note that I have seen a similar question on StackOverflow recently, however I
Note that my activity is NOT extending ListActivity; just Activity. I have a list
Please note that there is no limitation of memory. I need to insert int
Note that I'm asking about something that will call a callback function more often
(Note that I've searched online for the warnings I'm describing below, and have come
Note that I'm mirroring the example given here very closely. In fact, my situation
(Note that the examples are a simplification of my use case.) I have a
(note that I'm a total beginner in android programming) I have a class that

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.