Type casting void * withing classes?

This is a discussion on Type casting void * withing classes? within the C++ Programming forums, part of the General Programming Boards category; Im using mingw and everytime i try to type cast a void * to a special class of mine i ...

  1. #1
    some moron
    Guest

    Type casting void * withing classes?

    Im using mingw and everytime i try to type cast a void * to a special class of mine i get some bs about it being a "non-aggregate type" can anyone help?

  2. #2
    poo
    Guest
    o i forgot to mention its like this

    void *Account;

    and then i try to type cast Account to CPlayer so i can use the char *Name within CPlayer's... right now i got some ghetto system of resassigning like

    CPlayer *boo = (CPlayer *)Account;

    strcpy(boo->Name,"Bob");

    i want to be able to use it directly like this
    strcpy(Account->Name,"Bob");

    plzzz help!

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    You just can't do it directly like that. You'd have to do:

    strcpy(((CPlayer*)Account)->Name,"Bob");
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    right, a void * has no members. you have very little hope of calling functions off of it.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    la da da
    Guest
    aha thank you very much i didnt know to include the Account within the () i was doing thiS (CPlayer *)Account->Name; and getting the error:P thanks again!

  6. #6
    some moron
    Guest

    ooo another problem!!

    How do u type cast something like this

    CConnection *con;//which has a void * to Account which is a CPlayer which has a bool named Online

    like con->Account->Online = true; ?

    arr i have two books on C++ neither dable into type casting very well

  7. #7
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946

    Re: ooo another problem!!

    Originally posted by some moron
    How do u type cast something like this

    CConnection *con;//which has a void * to Account which is a CPlayer which has a bool named Online

    like con->Account->Online = true; ?

    arr i have two books on C++ neither dable into type casting very well
    ((CPlayer *) (con->Account))->Online = true;
    hello, internet!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. msvc just ate one of my source files
    By Eber Kain in forum C++ Programming
    Replies: 6
    Last Post: 07-01-2004, 05:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21