Is this a cast?

This is a discussion on Is this a cast? within the C++ Programming forums, part of the General Programming Boards category; int x; float a[10]; x = 1; a[0] = (float)x; This is a very simplified example of what their doing, ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    47

    Is this a cast?

    int x;
    float a[10];

    x = 1;
    a[0] = (float)x;

    This is a very simplified example of what their doing, but I'm used to seeing static_cast<float>. What's the difference here?

    Then, right below it, after initializing x to 0 again, they do this:

    t = float(x) / 35.0f;

    putting the paratheses around the variable instead of float.
    Last edited by subnet_rx; 12-28-2001 at 10:59 PM.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    32
    My book says something to the effect that parentheses around the type or around the variable are equivalent and inherited from C. C++ includes the more explicit cast form static_cast<float> and is equivalent to the other two.

    Seron

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Including The Right DLLs
    By bumfluff in forum Game Programming
    Replies: 8
    Last Post: 12-28-2006, 02:32 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Converting Double to Float
    By thetinman in forum C++ Programming
    Replies: 7
    Last Post: 06-17-2006, 02:46 PM
  4. errors in class(urgent )
    By ayesha in forum C++ Programming
    Replies: 1
    Last Post: 11-10-2001, 09:14 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 05:51 PM

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