《 C++ Primer》一书的第4.11.3章说:
In early versions of C++, an explicit cast took one of the following two forms:
type (expr); // function-style cast notation
(type) expr; // C-language-style cast notation
我得到C样式强制转换指针的工作方式如下:int* ip = nullptr;
void* vp = (void*) ip;
但是,我找不到如何使用函数样式的强制转换。下面的代码不起作用,我明白了为什么。我该如何工作?int* ip = nullptr;
void* vp = void*(ip);
最佳答案
您可以使用这种方式:
using voidPointer = void*;
int* ip = nullptr;
void* vp = voidPointer(ip);
之所以有效,是因为它使类型成为单个单词。另外,这也可以:typedef void* voidPointer;
关于c++ - 函数样式转换指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62881513/