Jump to content
  • Advertisement
Sign in to follow this  
Appmonster

(C++) Casting

This topic is 3779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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,

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by DevFred
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.


Shows how little i use it. Which is a good thing :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!