草庐IT

forward_static_call

全部标签

c++ - C++ 语言标准对 static_cast 如何处理减小整数的大小有何规定?

我想知道C++语言标准针对以下情况指定的规则:longx=200;shorty=static_cast(x);y是否保证为200,还是标准将其留给实现来决定?各种编译器对标准的遵守程度如何? 最佳答案 在本例中为static_cast是一个“显式类型转换”。该标准对4.7/3“积分转换”中的积分转换有这样的说法:Ifthedestinationtypeissigned,thevalueisunchangedifitcanberepresentedinthedestinationtype(andbit-fieldwidth);othe

c++ - "pure virtual method called"实现 boost::thread 包装器接口(interface)时

我有一个小包装器,它集中了与线程相关的内容:classThread{protected:boost::thread*m_thread;virtualvoidwork()=0;voiddo_work(){work();}public:Thread():m_thread(NULL){}virtual~Thread(){catch_up();deletem_thread;}inlinevoidcatch_up(){if(m_thread!=NULL){m_thread->join();}}voidrun(){m_thread=newboost::thread(boost::bind(&Thr

c++ - 从 std::call_once 抛出异常

C++标准对使用抛出异常的函数执行std::call_once(§30.4.4.2/2)作了如下说明:2/Effects:Anexecutionofcall_oncethatdoesnotcallitsfuncisapassiveexecution.Anexecutionofcall_oncethatcallsitsfuncisanactiveexecution.AnactiveexecutionshallcallINVOKE(DECAY_-COPY(std::forward(func)),DECAY_COPY(std::forward(args))...).Ifsuchacallto

c++ - 标准 :forward inside a template class

templateclassBlockingQueue{std::queuecontainer_;templatevoidpush(U&&value){static_assert(std::is_same::type>::value,"Can'tcallpushwithoutthesameparameterastemplateparameter'sclass");container_.push(std::forward(value));}};我希望BlockingQueue::push方法能够处理T类型对象的右值和左值引用,以将其转发到std::queue::push正确的版本。是像上面

c++ - static_assert 不会立即中断编译

代码示例:templatestructSUM{static_assert(x>=0,"Xmustbegreaterorequalto0");enum{VALUE=x+SUM::VALUE};};templatestructSUM{enum{VALUE=0};};intmain(){std::cout::VALUE为什么编译器不会在第一个static_assert时中断编译,而是继续工作直到达到最大实例化深度?Invoking:GCCC++Compilerg++-O0-g3-Wall-c-fmessage-length=0-std=c++11-MMD-MP-MF"src/Main.d"-

c++ - static_cast 从基析构函数到指向派生类的指针的安全性

这是问题的变体DowncastingusingtheStatic_castinC++和Safetyofinvaliddowncastusingstatic_cast(orreinterpret_cast)forinheritancewithoutaddedmembers关于~B中的行为,我不清楚标准中的短语“B实际上是D类型对象的子对象,结果指针指向D类型的封闭对象”。如果在~B中转换为D,此时它仍然是子对象吗?以下简单示例显示了问题:voidf(B*b);classB{public:B(){}~B(){f(this);}};classD:publicB{public:D(){}};s

c++ - 如何在 Xcode 中追踪 "libc++abi.dylib: Pure virtual function called!"

我有一个混合使用C++、Objective-C和Swift的多线程OSX应用程序。当我的应用程序关闭时,我在Xcode调试器窗口中看到:libc++abi.dylib:Purevirtualfunctioncalled!我知道这个错误通常是由在C++类构造函数或析构函数中调用虚函数引起的。有没有简单的方法可以找到它的位置?我所说的“简单”是指“不分析每个具有虚函数的类的每个构造函数和析构函数的每一行的调用树”。我没有看到堆栈跟踪。打印此消息时,调试器不会停止程序。从我的应用委托(delegate)的applicationDidTerminate方法记录的消息在此消息之前。我尝试在“所有

c++ - 在 C++ 中检测运算符是否存在和可调用(考虑 static_asserts)

给定2种类型T和U我想检测是否可以调用operator*在对象之间(即是否可以写t*u,其中t是T类型,u是U类型)我正在使用c++detectionidiom但由于它在我的编译器中还不可用,所以我自己实现了它structnonesuch{nonesuch()=delete;~nonesuch()=delete;nonesuch(nonesuchconst&)=delete;voidoperator=(nonesuchconst&)=delete;};namespacedetail{templateclassOp,class...Args>structdetector{usingval

c++ - 检测带有函数失败 static_assert 的成语

有没有办法使用detectionidiom(或其他方法)测试一个函数是否对给定的模板参数有效,如果它由于static_assert?而失败下面的示例说明了foo的有效性(失败的返回类型计算)按预期被检测到,但是bar的有效性(失败的static_assert)不是。#include#includetemplateusingvoid_t=void;templateclassOp,class...Args>structdetector:std::false_type{};templateclassOp,class...Args>structdetector>,Op,Args...>:std

c++ - 为什么在头文件中声明 "static const"成员会导致链接器错误?

我有一个这样的类声明(.h文件):structMyClass{staticconstuint32_tSIZE=sizeof(MyType);};将我的程序链接在一起时,出现MyClass::SIZE的链接器错误。nm确认符号未定义。http://forums.devshed.com/c-programming-42/linker-errors-undefined-reference-to-static-member-data-193010.html似乎解决了我的问题,表明“类静态对象也必须像普通全局变量一样在任何函数或类之外声明。”我有两个问题:这个解释对我的情况有效吗?如果是这样,您