奇怪的 static_cast 技巧?
在仔细阅读 Qt 源代码时,我遇到了这个 gem: template inline T qgraphicsitem_cast(const QGraphicsItem *item) { return int(static_cast(0)->Type…
C++ 中的措辞是什么?标准允许 static_cast(malloc(N));去工作?
据我理解 5.2.9 静态转换中的措辞,唯一允许 void* 到对象指针转换的结果是当 void* 首先是逆转换的结果。 在整个标准中,有大量对指针表示形式的引用…
C++:无法 static_cast 从 double* 到 int*
当我尝试使用 static_cast 将 double* 转换为 int* 时,出现以下错误: invalid static_cast from type ‘double*’ to type ‘int*’ 这是代码: #in…
static_cast 安全性
AFAIK,对于指针/引用 static_cast,如果此时编译器看不到类定义,则 static_cast 的行为将类似于 reinterpret_cast。 为什么 static_cast 对于指针/…
将 struct 转换为 unsigned char *
如何将以下 struct 转换为 unsigned char*? typedef struct { unsigned char uc1; unsigned char uc2; unsigned char uc3; unsigned char uc5; unsig…
static_cast 与 boost::shared_ptr?
与 boost::shared_ptr 等效的 static_cast 是什么? 换句话说, Base* b = new Derived(); Derived* d = static_cast(b); 使用 shared_ptr 时我该如何…
带有多个参数的 static_cast 是怎么回事?
谁能告诉我这个演员有什么效果(除了将 happyNumber 设置为 1337 之外),如果有的话,如果没有其他效果,我怎么能写这样的代码??? 这是编译器错误…
当将 void* 转换为任何内容时,我应该使用 static_cast 还是 reinterpret_cast
static_cast 和 reinterpret_cast 似乎都可以很好地将 void* 转换为另一种指针类型。 有充分的理由偏爱其中之一吗?…