大约有 118 项符合查询结果(耗时:0.0322秒) [XML]
总结const_cast、static_cast、dynamic_cast、reinterpret_cast - C/C++ - ...
总结const_cast、static_cast、dynamic_cast、reinterpret_cast简单总结:1)const_cast:移除const属性。2)static_cast:强转,与C类型转换类似,不检查类型来保证转换安全。也可用于指针的父类到子类的...简单总结:
1) const_cast:移除const属性。
...
Why use static_cast(x) instead of (int)x?
I've heard that the static_cast function should be preferred to C-style or simple function-style casting. Is this true? Why?
...
What is the difference between static_cast and C style casting?
Is there any reason to prefer static_cast<> over C style casting? Are they equivalent? Is their any sort of speed difference?
...
When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used?
...
static_cast is the first cast you should attempt to use. It does things like implicit conversions between types (such as int to float, or pointer to void*), and it can also call explicit conversion functions (or implicit ones...
Regular cast vs. static_cast vs. dynamic_cast [duplicate]
...
static_cast
static_cast is used for cases where you basically want to reverse an implicit conversion, with a few restrictions and additions. static_cast performs no runtime checks. This should be used if you know that you re...
How to cast int to enum in C++?
...
int i = 1;
Test val = static_cast<Test>(i);
share
|
improve this answer
|
follow
|
...
Why cast unused return values to void?
...afe to ignore it. Since you tagged the question as C++ you should be using static_cast:
static_cast<void>(fn());
As far as the compiler goes casting the return value to void has little meaning.
share
|
...
How to automatically convert strongly typed enum into int?
...ntegers, or even its underlying type - that's the idea. So you have to use static_cast to make conversion explicit.
If your only problem is scoping and you really want to have implicit promotion to integers, then you better off using not strongly typed enum with the scope of the structure it is dec...
Why is `std::move` named `std::move`?
...:swap:
template <class T>
void
swap(T& a, T& b)
{
T tmp(static_cast<T&&>(a));
a = static_cast<T&&>(b);
b = static_cast<T&&>(tmp);
}
One has to recall that at this point in history, the only thing that "&&" could possibly ...
When to use reinterpret_cast?
I am little confused with the applicability of reinterpret_cast vs static_cast . From what I have read the general rules are to use static cast when the types can be interpreted at compile time hence the word static . This is the cast the C++ compiler uses internally for implicit casts also.
...