Thread: casting

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    21

    casting

    Code:
    struct student{int*f;};
    int main(){
    struct student*student;
    int*p;
    int i;
    i=9;
    p=&i;
    student->f=(student->f*)p;
    }
    when I try to casting (student->f=(student->f*)p)an error appear like this expected expression before ‘)’ tokenI hope anyone can help me that's for all
    Last edited by Salem; 06-23-2012 at 07:20 AM. Reason: formatting - learn it!

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Dude, don't threadjack. And learn how to post code, that's impossible to read.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    split and moved.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    Looky, indentation...
    Code:
    struct student
    {
        int*f;
    };
    
    int main(){
        struct student*student;
        int*p;
        int i;
        i=9;
        p=&i;
        student->f=(student->f*)p;
    }
    You can't cast to student->f* because student->f* is not a type. You can only cast to types - usually to change the type of something.

    student->f is of type int* and so is p, so you don't need a cast.

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    And before you can assign anything to student->f, you have to initialize student.

    Bye, Andreas

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advantages of c++ type casting over c type casting
    By kaibalya2008 in forum C++ Programming
    Replies: 10
    Last Post: 05-05-2009, 11:09 AM
  2. Casting
    By c++0x in forum C Programming
    Replies: 9
    Last Post: 12-12-2008, 08:25 PM
  3. Casting
    By morvick in forum C++ Programming
    Replies: 2
    Last Post: 06-17-2007, 11:06 PM
  4. ray casting
    By lambs4 in forum Game Programming
    Replies: 62
    Last Post: 01-09-2003, 06:57 PM