Python
Java
PHP
IOS
Android
Nodejs
JavaScript
Html5
Windows
Ubuntu
Linux
static_cast 到相同类型会引入运行时开销吗?
我有一个结构模板 有两种类型 T and S 并在某些时候使用static cast从一种类型转换为另一种类型 经常出现这样的情况T and S是同一类型 设置的简化示例 template
c
overhead
staticcast
当将 void* 转换为任何内容时,我应该使用 static_cast 还是 reinterpret_cast
Both static cast and reinterpret cast似乎适合铸造void 到另一个指针类型 是否有充分的理由偏爱其中之一 Use static cast 这是最精确的转换 准确地描述了此处进行的转换 有一个误解 认为使
c
pointers
staticcast
reinterpretcast
使用 C++ 风格转换从 Void* 转换为 TYPE*:static_cast 或 reinterpret_cast
因此 如果您从 Void 转换为 Type 或从 Type 转换为 Void 您应该使用 void func void p Params params static cast
c
casting
staticcast
reinterpretcast
如何在 C++17 中将抛出函数指针静态转换为 noexcept?
C 17 使noexcept函数类型的一部分 它还允许隐式转换noexcept指向可能抛出函数指针的函数指针 void ptr to noexcept noexcept nullptr void ptr to throwing ptr to
c
C17
functionpointers
staticcast
noexcept
static_cast 向下转换实际上不是对象类型的类型是否是未定义的行为?
这是一个关于 stackoverflow 的讨论 https stackoverflow com questions 332030 when should static cast dynamic cast const cast and re
c
languagelawyer
staticcast
static_cast<> 和 C 风格转换有什么区别? [复制]
这个问题在这里已经有答案了 有什么理由更喜欢static cast lt gt 超过 C 风格的铸造 它们相等吗 有什么速度差异吗 C 风格的转换由编译器检查 C 风格的转换不是这样 并且可能在运行时失败 另外 C 风格的转换很容易搜索 而
c
casting
staticcast
C2440 static_cast 无法从基类转换为派生类
我试图理解为什么使用指针从基类到派生类的转换编译得很好 但使用非指针对象进行转换会产生错误 C2440 下面我有一个基类ThreadedMessage这是由类继承的GPSMessage struct ThreadedMessage Thre
c
casting
polymorphism
staticcast
当两个链接的 static_cast 可以完成它的工作时,为什么我们在 C++ 中需要 reinterpret_cast 呢?
说我想投A to char 反之亦然 我们有两种选择 我的意思是 我们很多人认为我们有两种选择 because两者似乎都有效 因此造成混乱 struct A int age char name 128 A a char buffer sta
c
casting
reinterpretcast
staticcast
为什么使用 static_cast
(x) 而不是 (T)x?
我听说static cast函数应该优先于 C 风格或简单函数风格的转换 这是真的 为什么 主要原因是经典的 C 类型转换不区分我们所说的static cast lt gt reinterpret cast lt gt const cast
c
casting
staticcast
C++ static_cast 运行时开销
请参阅下面的代码 a 在这种情况下 简单继承 无虚拟成员 B df 中的静态转换是否有任何开销 无论如何 我发现类似问题的一些相互矛盾的答案 这就是我问的原因 b 我正在考虑制作const M1 funcA 中的 private 并引入新的
c
Runtime
overhead
staticcast
为什么 std::Optional 的强制转换运算符会被忽略?
这段代码 include
c
casting
operatoroverloading
C17
staticcast
为什么表达式上的 static_cast 具有分布式作用?
我需要取 2 个无符号 8 位值并减去它们 然后将该值添加到 32 位累加器 8 位减法可能会下溢 但没关系 unsigned int 下溢是已定义的行为 因此没有问题 我希望static cast
c
casting
staticcast
为什么我必须重新解释指针指针?
So this static cast代码是完全合法的 int n 13 void pn static cast
c
voidpointers
reinterpretcast
staticcast
doublepointer
遍历继承层次结构的 static_cast 与dynamic_cast
我看到一本关于 C 的书提到 使用静态强制转换来导航继承层次结构比使用动态强制转换更有效 Example include
c
casting
RTTI
dynamiccast
staticcast
static_cast 从 Derived* 到 void* 到 Base*
我想将一个指向派生类成员的指针转换为void 并从那里指向基类的指针 如下例所示 include
c
staticcast
对重载函数的不明确调用
我有两个功能 void DoSomething const tchar apsValue void DoSomething size t aiValue 现在我想将 0 作为 size t 传递 DoSomething 0 编译器抛出错误
c
overloading
staticcast
几乎所有 pod 数据都可以用reinterpret_cast(布局兼容性是否足够)
我正在尝试了解static cast and reinterpret cast 如果我是正确的 标准 9 2 18 说的是reinterpret castpod 数据是安全的 指向 POD 结构对象的指针 使用适当转换reinterpret
c
reinterpretcast
staticcast
从基类指针访问子类成员 C++
我有一系列自定义类 Student 对象 CourseStudent和ResearchStudent都继承自Student 并且Student的所有实例都是其中之一 我有一个函数来遍历数组 确定每个学生的子类型 然后对它们调用特定于子类型的
c
inheritance
virtualfunctions
dynamiccast
staticcast
std::aligned_storage 的 static_cast 和 reinterpret_cast
有人可以解释一下关于投射的代码吗http en cppreference com w cpp types aligned storage please 可以用下面的代码 return static cast
c
Alignment
reinterpretcast
staticcast
C++:偏移到 std::vector 迭代器的正确转换是什么?
我有一个函数需要std vector双精度数 并将它们复制到另一个向量 但以特定的偏移量 假设有足够的空间 void copy stuff const std vector
c
C11
vector
offset
staticcast
1
2
»