Thread: Type casting void * withing classes?

  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,708
    You just can't do it directly like that. You'd have to do:

    strcpy(((CPlayer*)Account)->Name,"Bob");
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  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
    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