cast or C Style type casting
This question already has an answer here:
Casts should be used rarely, and cautiously, and it is a lot easier to spot when you're abusing the system if you write:
char *x = const_cast<char *>(some_const_char_pointer_expression);
than if you disguise it with:
char *x = (char *)some_const_char_pointer_expression;
So, use the explicit, controlled, verbose notation because it encourages you to avoid casts, and to use the correct, precise cast when you must use one.
C style cast is more general. It 'chooses' from const_cast , static_cast , const_cast with static_cast , dynamic_cast , then dynamic_cast with const_cast and finally reinterpret_cast , reinterpret_cast with const_cast . So, as you see, there is pretty much difference between c-cast and reinterpret_cast , as C-cast cast goes with static and dynamic cast first.
If you write in C++, you should prefer one of casts above instead of C-style cast. They are more explicit. But C-style cast is not a very-very-very bad style.
链接地址: http://www.djcxy.com/p/28708.html上一篇: C的main()函数的有效签名是什么?
下一篇: 演员表或C风格类型演员
