static-cast

static-cast

文章 0 浏览 3

奇怪的 static_cast 技巧?

在仔细阅读 Qt 源代码时,我遇到了这个 gem: template inline T qgraphicsitem_cast(const QGraphicsItem *item) { return int(static_cast(0)->Type…

梦太阳 2024-09-04 06:42:36 8 0

C++ 中的措辞是什么?标准允许 static_cast(malloc(N));去工作?

据我理解 5.2.9 静态转换中的措辞,唯一允许 void* 到对象指针转换的结果是当 void* 首先是逆转换的结果。 在整个标准中,有大量对指针表示形式的引用…

树深时见影 2024-08-28 13:24:58 17 0

C++:无法 static_cast 从 double* 到 int*

当我尝试使用 static_cast 将 double* 转换为 int* 时,出现以下错误: invalid static_cast from type ‘double*’ to type ‘int*’ 这是代码: #in…

ぶ宁プ宁ぶ 2024-08-25 22:02:27 7 0

static_cast 安全性

AFAIK,对于指针/引用 static_cast,如果此时编译器看不到类定义,则 static_cast 的行为将类似于 reinterpret_cast。 为什么 static_cast 对于指针/…

盛夏已如深秋| 2024-08-23 10:52:51 12 0

施工期间向下浇筑安全吗?

我有一个类层次结构,我知道给定的类 (B) 总是会派生到第二个类 (D)。 在 B 的构造函数中,如果我确定在整个构造完成之前没有人会尝试使用它,那么将 …

_失温 2024-07-29 21:00:11 12 0

C++,静态检测具有不同地址的基类?

如果我有一个具有多个基类的派生类,则每个基类的每个 this 指针都将与派生对象的 this 指针不同,只有一个除外。 给定继承层次结构中的两种类型,我…

余生共白头 2024-07-26 20:44:59 12 0

将 struct 转换为 unsigned char *

如何将以下 struct 转换为 unsigned char*? typedef struct { unsigned char uc1; unsigned char uc2; unsigned char uc3; unsigned char uc5; unsig…

相权↑美人 2024-07-26 14:55:52 10 0

static_cast 和 Implicit_cast 有什么区别?

什么是implicit_cast? 我什么时候应该选择implicit_cast而不是static_cast?…

最美的太阳 2024-07-21 04:48:20 12 0

C++ 语法问题

下面的语法是什么意思? typedef void* hMyClass; //typedef as a handle or reference hMyClass f = &something; const MyClass& foo = static_cast(…

涫野音 2024-07-17 04:52:49 9 0

static_cast 与 boost::shared_ptr?

与 boost::shared_ptr 等效的 static_cast 是什么? 换句话说, Base* b = new Derived(); Derived* d = static_cast(b); 使用 shared_ptr 时我该如何…

前事休说 2024-07-14 12:50:59 14 0

带有多个参数的 static_cast 是怎么回事?

谁能告诉我这个演员有什么效果(除了将 happyNumber 设置为 1337 之外),如果有的话,如果没有其他效果,我怎么能写这样的代码??? 这是编译器错误…

迷爱 2024-07-14 05:18:30 12 0

当将 void* 转换为任何内容时,我应该使用 static_cast 还是 reinterpret_cast

static_cast 和 reinterpret_cast 似乎都可以很好地将 void* 转换为另一种指针类型。 有充分的理由偏爱其中之一吗?…

夏九 2024-07-08 14:43:51 11 0

为什么使用 static_cast(x) 而不是 (T)x?

我听说 static_cast 函数应该优先于 C 风格或简单函数风格的转换。 这是真的? 为什么?…

巴黎夜雨 2024-07-04 18:58:49 9 0
更多

推荐作者

已经忘了多久

文章 0 评论 0

15867725375

文章 0 评论 0

LonelySnow

文章 0 评论 0

走过海棠暮

文章 0 评论 0

轻许诺言

文章 0 评论 0

信馬由缰

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文