static-cast专题提供static-cast的最新资讯内容,帮你更好的了解static-cast。
我有一个结构模板,它有两种类型(T和S),在某种程度上使用一个static_cast从一种类型转换为另一种类型.通常情况下,T和S是相同的类型. 一个简化的设置示例: template <typename T, typename S = T> struct foo { void bar(T val) { /* ... */ some_other_function(stati
我需要为回调函数编写代码(它将在ATL中调用,但这并不重要): HRESULT callback( void* myObjectVoid ) { if( myObjectVoid == 0 ) { return E_POINTER; } CMyClass* myObject = static_cast<CMyClass*>( myObjectVoid );
为什么我不能使用reinterpret_cast操作符进行这样的转换? enum Foo { bar, baz }; void foo(Foo) { } int main() { // foo(0); // error: invalid conversion from 'int' to 'Foo' // foo(reinterpret_cast<Foo>(0)); // error
At a reply of a blog post of Raymond Chen, 提问者指出 Raymond, I believe the C++ example is not correct since the position of the base class subobject in the derived class is unspecified according to ISO C
我见过人们建议使用static_cast< SomeType *>(static_cast< void *>(p))而不是重新解释强制转换. 我不明白为什么这样更好,有人可以解释一下吗? 为了论证,这里是一个需要reinterpret_cast的示例场景: DWORD lpNumberOfBytes; ULONG_PTR lpCompletionKey; LPOVERLAPPED lpOverla