Results 1 to 6 of 6

Thread: casting - HARD

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    casting - HARD

    how can i cast a class i made into a void* and back again?
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Why do you want to? You very rarely need to cast a pointer to a void*.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    um, actually its this other guy who wants to know, i think he's trying to create a new thread but i don't remember which API it was he was using, i don't think it was CreateThread(Ex)
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    _beginthread[ex]?

    In that case just something like:
    Code:
    ... threadproc(void *param) {
        myclass *mc = dynamic_cast<myclass*>(param);
    }
    
    // ...
    myclass mc;
    
    _beginthread(..., &mc, ...);
    Can't remember any of the threading details right now
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I think you need a reinterpret_cast, dynamic_cast won't work (works only for casting among class hierarchies with RTTI enabled). I think static_cast for something* to void* and reinterpret_cast for void* to something*.

    Clashes of good C++ and C APIs always favor C.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You're right...I'm just too used to using dynamic_cast
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width