![]() |
static_cast
static_cast is used to convert between enum and integer.
the same can be done using c-type casting. then why static_cast is used ?? |
Re: static_cast
On Nov 17, 8:16*am, asit <lipu...@gmail.com> wrote:
> static_cast is used to convert between enum and integer. > > the same can be done using c-type casting. > > then why static_cast is used ?? a c-style cast can do a lot of things. By using a static_cast you are expressing your intent more clearly. The "new" style casts are easier to find with grep and standout in the code. Casts should be few and far between. They can be the source of subtle (and not so subtle) bugs. The ability to easily find all the casts in your source code can be helpful. char s; strcpy ((char*)s, "hello"); |
Re: static_cast
On Nov 17, 9:16*am, asit <lipu...@gmail.com> wrote:
> static_cast is used to convert between enum and integer. > > the same can be done using c-type casting. > > then why static_cast is used ?? 1. C-style casting casts *everything* away, whereas C++-style cast offers more control. 2. C++-style casts are much easier to find in sources; that's important, see 3. 3. Casting is a sign of a poor design more often than not. Because C++- style cast is pain to read and write, it promotes thinking and design over quick hacks ;-). |
| All times are GMT. The time now is 02:33 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.