(C++) Casting
Stumbled on this thing called casting, had a look around and found a decent website that shows you the many ways to do it, but I don't know what the standard way of doing it is and now i'm confused (lol), can anybody clear casting up for me?
In C++ you should be casting using one of the following, as appropriate:
static_cast<>()
dynamic_cast<>()
reinterpret_cast<>()
Googling for each of those will yield examples of usage.
Hope that helps,
static_cast<>()
dynamic_cast<>()
reinterpret_cast<>()
Googling for each of those will yield examples of usage.
Hope that helps,
thank you, will do! Just figured out this cast lol:
int a = 97;char b = 'z'; b = (char) a; // Turns b into a (from z)
Quote:Original post by Appmonster
thank you, will do! Just figured out this cast lol:
*** Source Snippet Removed ***
With that cast it is important to note that you are truncating the data stored in the integer since that is most likely 32 bits and the char is most likely 8 bits. So the first 8 bits of the integer are preserved, the rest is lost.
Quote:Original post by Dave
In C++ you should be casting using one of the following, as appropriate:
static_cast<>()
dynamic_cast<>()
reinterpret_cast<>()
You forgot const_cast.
Quote:Original post by DevFredQuote:Original post by Dave
In C++ you should be casting using one of the following, as appropriate:
static_cast<>()
dynamic_cast<>()
reinterpret_cast<>()
You forgot const_cast.
Shows how little i use it. Which is a good thing :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement