static-cast
Why can't static_cast be used to down-cast when virtual inheritance is involved?
Consider the following code: struct Base {}; struct Derived : public virtual Base {}; void f() { Base* b = new Derived;[详细]
2023-04-05 22:56 分类:问答interpret unsigned as signed
I\'m working on an embedded platform (ARM) and have to be careful when dealing with bit patterns. Let\'s pretend this line is beyond my influence:[详细]
2023-04-03 19:39 分类:问答C++ to C#, static_cast into enum
I\'m trying to convert a bit of VC 6.0 C++ code to C#. Specifically, I\'m parsing through a binary dat file and I\'ve run into a problem converting this bit of code:[详细]
2023-03-24 12:17 分类:问答C++ When should we prefer to use a two chained static_cast over reinterpret_cast
First of all, this is not a duplicate of Why do we have reinterpret_cast in C++ when two chained static_cast can do it\'s job?.[详细]
2023-03-18 20:13 分类:问答May I have a real life example where casting through void* works and reinterpret_cast doesn't?
There\'s a set of questions regarding c开发者_StackOverflow中文版ross-casts (cast from T1* to unrelated T2*), for example this and this. The answer usually goes like this: reinterpret_cast is implemen[详细]
2023-03-18 03:49 分类:问答C++ static_cast runtime overhead
See the code below. a) Does, in this case (simple inheritance, no virtual members), the static cast in B::df() have any overhead (whatsoever)? I found some conflicting answers to similar questions, t[详细]
2023-03-14 14:59 分类:问答Downcast in a diamond hierarchy
Why static_cast cannot downcast from a virtual base ? struct A {}; struct B : public virtual A {}; struct C : public virtual A {};[详细]
2023-03-06 23:06 分类:问答Why go through the trouble of static_cast-ing a number to a double?
Ran across this in code I\'m working 开发者_StackOverflow社区through: double part2 = static_cast<double>(2) * somthing1[详细]
2023-02-19 21:49 分类:问答Templated assignment operator question
I want to make sure that *this != &rhs in the assignment operator. But it won\'t compile. Any suggestions?[详细]
2023-02-15 12:11 分类:问答reinterpret_cast for almost pod data (is layout-compatibility enough)
I am trying to learn about static_cast and reinterpret_cast. If I am correct the standard (9.2.18) says that reinterpret_cast for pod data is safe:[详细]
2023-02-12 01:24 分类:问答