Thread: Noob here, having trouble with simple program

  1. #16
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Wait, you can assign to like an lvalue, right? Isn't (doube ) my_value an rvalue?

  2. #17
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What? (double)SomeValue is a cast not an assignment. And no you can't cast a lvalue in a calculation.

    Jim

  3. #18
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by MutantJohn View Post
    Also, I didn't know that, is it really that easy to cast away constness using that? I always thought you had to do more nefarious things to effectively undermine const-ness
    Const casting is actually one of the first things C++ tries to do to resolve (type)foo, it then tries static_cast, then a combination of static_cast and const cast to get to type. If all of those fail, then reinterpret_cast is used - the most permissive cast. The danger in C casting is the tendency to devolve into reinterpret_cast from some other mistake or from being short sighted about design.

    Take this code, which only reinterpret_cast would compile.
    Code:
    int *v = something;
    double d = double(v);
    Forgetting the * is disastrous here.

    C casting can be shorthand for something that you're sure will succeed before reinterpret_cast is used, so I don't necessarily blame you, but yeah it can remove const.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 02-21-2011, 10:21 PM
  2. Replies: 1
    Last Post: 04-12-2009, 04:21 AM
  3. noob help on simple program
    By halfpint101 in forum C++ Programming
    Replies: 3
    Last Post: 12-18-2007, 07:29 PM
  4. Replies: 2
    Last Post: 11-17-2007, 04:25 PM
  5. Having trouble with a simple program......
    By Redpred in forum C Programming
    Replies: 9
    Last Post: 08-11-2006, 04:39 AM

Tags for this Thread