首页 > TAG信息列表 > static-cast

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

如果我有一个具有多个基数的派生类,则每个基数的每个this指针都将与派生对象的this指针不同,除了一个.给定继承层次结构中的两种类型,我想在编译时检测它们是否共享相同的this指针.这样的事情应该起作用,但是不起作用: BOOST_STATIC_ASSERT(static_cast<Base1*>((Derived *)0xDEADB

c-std :: aligned_storage的static_cast和reinterpret_cast

有人可以解释一下http://en.cppreference.com/w/cpp/types/aligned_storage中的转换代码吗? 可以下面的代码 return *static_cast<const T*>(static_cast<const void*>(&data[pos])); 被取代 return *reinterpret_cast<const T*>(&data[pos]); ? 为什么在这里使用两个铸造? 非常

c – static_cast’d指针值

在当前的标准草案(和C 17)中,this是关于static_casting a void *的: A prvalue of type “pointer to cv1 void” can be converted to a prvalue of type “pointer to cv2 T”, where T is an object type and cv2 is the same cv-qualification as, or greater cv-qualificatio

c – 使用static_cast(或reinterpret_cast)进行无效向下转换的安全性,无需添加成员即可继承

我想知道标准对以下代码的安全性的说法: class A { int v; }; class B: public A { }; // no added data member A a; B& b = static_cast<B&>(a); 显然,a的运行时类型是A,而不是B,因此强制转换实际上并不是类型安全的.但是,由于没有添加任何成员而且没有任何内容是虚拟的,IMO的

转换为不同的基类会产生不同的结果. C

也许我的问题没有完美形成,但我的代码将使一切都清楚. #include <iostream> using namespace std; struct A{int n;}; struct B{int n;}; struct C : A, B{}; int main() { C c; C* pc = &c; std::cout<<"TEST1"<<std::endl; cout << stati

c – 我应该使用static_cast还是INT64_C来便携地分配64位常量?

将64位常量指定为 int64_t foo = 0x1234LL; 不可移植,因为long long不一定是int64_t.这篇文章Which initializer is appropriate for an int64_t?讨论了从< stdint.h>中使用INT64_C()宏,但是也不能使用static_cast作为 int64_t foo = static_cast<int64_t>(0x1234); ? 我应该选

C重载函数指针歧义

我正在尝试传递一个重载的函数指针,如下面的示例代码所示. class Sample { uint32_t method(char* input1, double input2); uint32_t method(double input1); } template<class T, class... Args) void processInput(T &&t, Args&&... a) { std::packaged_task<uint32_t(

c – 使用weak_ptr作为参数的函数重载分辨率

我有: class A : public std::enable_shared_from_this<A> {...}; class B : public A {...}; void doCoolStuff(std::weak_ptr<A> obj) {...} void doCoolStuff(std::weak_ptr<B> obj) { ... doCoolStuff(std::static_pointer_cast<A>(obj.lock

C:对std :: vector迭代器进行offseting的正确演员是什么?

我有一个函数,它接受一个std :: vector of double,并将它们复制到另一个向量,但是在一个特定的偏移处(假设有足够的空间): void copy_stuff(const std::vector<double> & data, std::vector<double> & dest, size_t dest_offset) { std::copy(

c – 我的老师不像其他人一样打字.有谁知道他在做什么?

我的老师在我们的一个铸造示例中包含了以下几行. c是Circle类的一个对象,它继承自Point类.在我搜索问题的答案“我可以将类Point的对象转换为Circle类型吗?”我发现他使用的语法与我曾经使用的每个网站不同.这些网站都使用static_cast和dynamic_cast语法.他不会在测试中使用static_c