草庐IT

forward_static_call

全部标签

C++:莫名其妙的 "pure virtual function call"错误

我在使用MicrosoftVisualC++2015时遇到了一些困难,但能够用一个小程序重现该问题。给定以下类:classBaseClass{public:BaseClass():mValue(0),mDirty(true){}virtual~BaseClass(){}virtualintgetValue()const{if(mDirty)updateValue();returnmValue;}protected:virtualvoidupdateValue()const=0;mutableboolmDirty;mutableintmValue;};classDerivedClass:

c++ - gcc 与 clang、msvc 和 icc : Is this function call ambiguous?

我能得到的所有编译器都同意这很好:templateautofoo(Check,T...)->void;templateautofoo(int,T...)->void;intmain(){foo(7,"");}但是,根据gcc,以下代码(带有不能从函数参数推导的前导模板参数)是不明确的:templateautobar(Check,T...)->void;templateautobar(int,T...)->void;intmain(){bar(7,"");//ambiguousaccordingtogccbar(7);//justfine}另一方面,clang、msvc和icc对此非常满

c++ - 使用 std::forward 而不是 std::move 来初始化对象有什么好处吗?

我有一个函数模板,它采用某种可调用类型的参数,并使用std::bind为原始可调用对象创建一个具有预定义参数值的新可调用对象。我用转发引用参数和std::forward编写了它,如下所示:templateautomake_example_caller(F&&f){returnstd::bind(std::forward(f),123,456,789);}cppreferencedocumentationforstd::bind表示绑定(bind)对象“包含一个由std::decay::type构造的std::forward(f)类型的成员对象”。由于std::bind将函数转发给它的内

c++ - 通过 decltype 表达式调用时 static_assert 是否应该工作?

我预计以下代码会因最后一行的static_assert检查而失败。但是在MSVC2015和gcc6.2中,它编译成功。它确实无法按预期在clang3.9中进行编译。这是编译器错误还是static_assert在decltype()中不起作用?#include#includetemplatestructWrapper{};templateconstexprstd::tupleoperator|(Wrapper,Wrapper){static_assert(std::is_same::value==false,"can'tcombinetwoofthesametype");returnst

c++ - std::forward_list 成员可以实现为静态的吗?

std::forward_list提供了insert_after和erase_after成员,它们可能不需要实际访问std::forward_list对象。因此,它们可以作为static成员函数实现,并且可以在没有列表对象的情况下被调用——对于想要从列表中删除自身的对象很有用,这是一种非常常见的用法。编辑:此优化仅适用于std::allocator或用户定义的无状态分配器的forward_list特化。符合标准的实现可以做到这一点吗?§17.6.5.5/3说AcalltoamemberfunctionsignaturedescribedintheC++standardlibrarybe

c++ - 轻松地将许多重要的 "static library projects"重构为 "dll projects"

我有6个静态库项目:--Math-ECS:dependsonMath-Utility:dependsonECS-Physics:dependsonUtility-Graphics:dependsonUtility-BaseGame:dependsonPhysicsandGraphics-Somegame(.exe):dependsonBaseGame(The"depends"hereistransitivee.g.BaseGamealsodependsonECS.)我通过“静态库”技术成功地使用了6个项目。今天听说动态库可以减少编译时间(暂且不讨论是否属实),所以我阅读了以下链接并成功

c++ - 为什么我不能使用 static_cast<int&> 将整数引用参数传递给 C++ 中的函数?

我在C++程序中有一个枚举参数,我需要使用一个通过参数返回值的函数来获取它。我首先将其声明为int,但在代码审查时被要求将其键入为枚举(ControlSource)。我这样做了,但它破坏了Get()函数——我注意到C风格的转换为int&解决了这个问题,但是当我第一次尝试用static_cast修复它时,它没有编译。为什么会这样,为什么当eTimeSource是一个int时根本不需要强制转换来通过引用传递整数?//GetCuePropertyValuesignatureis(intcueId,intpropertyId,int&value);ControlSourceeTimeSourc

c++ - 我可以在类定义中放置 "non-static blocks"代码吗?

C++中有非静态block吗?如果不是,如何优雅地模拟?我想替换像这样的东西:-classC{public:voidini(){/*somecode*/}};classD{std::vectorregis;//willini();laterpublic:Cfield1;public:Cfield2;public:Cfield3;//wheneverIaddanewfield,Ihaveto...#1public:D(){regis.push_back(&field1);regis.push_back(&field2);regis.push_back(&field3);//#1...al

c++ - 为什么 `const int ci = 2; std::forward<int>(ci);` 不起作用以及如何修复/解决它?

简单的问题,为什么不thefollowing工作(意味着ci的拷贝)?#includeintmain(){constintci=2;std::forward(ci);}prog.cpp:Infunction'intmain()':prog.cpp:6:23:error:nomatchingfunctionforcallto'forward(constint&)'问题在编写一些模板内容时表现出来,我有一个简单的holder类型,如下所示。为了避免不必要的拷贝,我尽可能使用完美转发,但事实证明这似乎是问题的根源。templatestructholder{Tvalue;holder(T&&v

c++ - 如何告诉 static_assert constexpr 函数参数是 const?

我有一个看起来像这样的constexpr函数:constexprintfoo(intbar){static_assert(bar>arbitrary_number,"Usealowernumberplease");returnsomething_const;}但是,用GCC4.6.3编译这个一直告诉我错误:'bar'不能出现在常量表达式中我试过类似的东西constexprintfoo(constexprconstintbar){static_assert(bar>arbitrary_number,"Usealowernumberplease");returnsomething_cons