Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Casting from pointer to int

Posted on 2000-04-04
5
246 Views
Last Modified: 2010-04-02
This code works:
  if ((int) pNode()->pUserField() == 2) .....

but am not sure how to do the opposite ie. plug a value back into the object pNode.   I have tried

  pNode()->pUserField() = (void *) 2;

but this doesn't compile.  How do I set the pUserField to an integer value?

0
Comment
Question by:abulka
5 Comments
 

Expert Comment

by:ottenm
ID: 2686170
Short answer?  Use another function (not pUserField()).  i.e., pUserField() is a function that, if the second line you show doesn't compile, does not return something that can show up on the left hand side of an assignment operator (an "l-value").  Maybe you can rewrite the function pUserField() (and note, it is a function, not a variable, as the name would lead you to believe) to return by reference.  Then you'd be all set!
0
 

Author Comment

by:abulka
ID: 2686199
I am using a 3rd party library and cannot rewrite or add new functions.  It should be possible to do with the existing function.  Here is more info on the UserField property:



//
// This method sets a void pointer to a user field. This pointer is
// originally initialized to NULL.
//

void * TSDigraph::pUserField(void * pUserField);


//
// This method gets a void pointer to a user field. This pointer is
// originally initialized to NULL.
//

void * TSDigraph::pUserField();


0
 
LVL 3

Accepted Solution

by:
GlennDean earned 5 total points
ID: 2686239
Instead of writing
pNode()->pUserField() = (void *) 2;
write
pNode()->pUserField((void *)2);
   Glenn
0
 
LVL 3

Expert Comment

by:mnewton022700
ID: 2686254
I work for Tom Sawyer and I can tell you that Glenn is definitely right. He fully deserves the enormous 5 point reward :)
0
 

Author Comment

by:abulka
ID: 2686327
Seems to work.  Much appreciated!  Thanks to mnewton, too.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SendMessage fails while PostMessage works 2 122
C++ standard library based binary archive format 6 104
C++ to C# code conversion issue 4 111
Why isn't object file created? 6 68
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question