草庐IT

ref-parameters

全部标签

c++ - "trailing parameter pack"到底是什么

在解决函数模板重载之间的歧义时,会执行部分排序(参见here的一些解释)。在那个网站上,我们还了解到Incaseofatie,ifonefunctiontemplatehasatrailingparameterpackandtheotherdoesnot,theonewiththeomittedparameterisconsideredtobemorespecializedthantheonewiththeemptyparameterpack.现在,我想知道尾随参数包到底是什么。如果有的话templatestructtuple{/*...*/};templatevoidfoo(tupl

c++ - 编译器错误 : Function call with parameters that may be unsafe

得到了一些不是我的代码并且它产生了这个警告atm:iehtmlwin.cpp(264):warningC4996:'std::basic_string::copy':Functioncallwithparametersthatmaybeunsafe-thiscallreliesonthecallertocheckthatthepassedvaluesarecorrect.Todisablethiswarning,use-D_SCL_SECURE_NO_WARNINGS.SeedocumentationonhowtouseVisualC++'CheckedIterators'with[_

c++ - 让 shared_ptr refs 出现在 doxygen 协作图中

我已经做了足够多的谷歌搜索知道如果我有什么喜欢classSubObject{public://blahblahblah};classAggregate{public:boost::shared_ptrm_ptr;};我可以让Doxygen创建“正确”的协作图如果我有一个像这样的虚拟声明namespaceboost{templateclassshared_ptr{T*dummy;};}在我的头文件中。我的问题是:我如何让它在我的所有项目中发挥作用以及我所有的标题,而不必实际包含该行在每个文件中? 最佳答案 呵呵....我觉得自己回答自

c++ - 使用强 typedef 作为 Boost Parameter 库的更轻量级替代方案?

我经常使用Booststrongtypedef实用程序来boost我的程序的安全性。例如通过编写如下代码:BOOST_STRONG_TYPEDEF(int,X)BOOST_STRONG_TYPEDEF(int,Y)BOOST_STRONG_TYPEDEF(int,Width)BOOST_STRONG_TYPEDEF(int,Height)structRect{Rect(Xx,Yy,Widthw,Heighth);};//Usage:Rectrect(X(10),Y(20),Width(800),Height(600));这里的强typedefboost了代码的可读性和安全性。(如果参数

c++ - 正确使用 Eigen::Ref<> 类

Eigen引入了Ref类来编写以Eigen对象为参数的函数,而无需使用不必要的临时变量,当不需要编写模板函数时。可以阅读here.当进一步搜索互联网时,我发现了几个使用Ref类的不同参数声明。在Eigen文档中,他们使用constEigen::Ref&对于第一个示例中的只读参数。在第二个例子中Eigen::Ref为读写参数引入,但这里是constEigen::Ref用于只读参数(无引用)。所以我的问题是:以下声明有什么区别,什么时候使用?`constEigen::Ref&constEigen::RefconstEigen::Ref&constEigen::RefEigen::Ref&E

c++ - 构造函数 : difference between defaulting and delegating a parameter

今天,我偶然发现了thesestandarddeclarationsstd::vector构造函数://untilC++14explicitvector(constAllocator&alloc=Allocator());//sinceC++14vector():vector(Allocator()){}explicitvector(constAllocator&alloc);这种变化可以在大多数标准容器中看到。一个稍微不同的例子是std::set://untilC++14explicitset(constCompare&comp=Compare(),constAllocator&al

c++ - 奇怪的编译器错误 : Cannot convert parameter from 'int' to 'int &&'

这到底是怎么回事?我正在尝试创建一对int和一个string如果我使用“魔术值”但似乎无法传递变量,我可以创建这对.std::vector>num_text;std::stringtext="Smeg";intnum=42;//Worksfinenum_text.push_back(std::make_pair(42,std::string("Smeg")));//Cannotconvertparameter2from'std::string'to'std::string&&'num_text.push_back(std::make_pair(42,text));//Cannotcon

c++ - 忽略: warning: unused parameter有什么后果

我正在处理一个C++项目,我注意到我们有许多关于未使用参数的警告。如果忽略这些警告会有什么影响? 最佳答案 带有未使用参数的函数在以下情况下可能存在真正的错误:有一个输出参数,没有被赋值或写入,导致调用者的值未定义。其中一个参数是回调函数指针,您必须调用它而忘记这样做。如果函数中有很多#ifdef,可能会发生这种情况。你声明了一个同名的局部变量,它隐藏了一个参数,随后在函数中使用了错误的值。不使用输入参数可能是无害的,但您可以通过强制转换在函数开头显式标记未使用的输入参数来减少噪音以查看有用的警告它到void(适用于C和C++):(

c++ - 错误消息 "undefined reference to template function passed as template parameter"

当我将模板函数作为基类的模板参数传递时,链接器提示它无法链接该函数:#includetemplateinlineintidentity(){returnI;}//templateinlineintidentity(){return20;}templateclassBase{public:intf(){returnfn();}};templateclassDerived:publicBase>{public:intf2(){returnf();}};intmain(intargc,char**argv){Derivedo;printf("result:%d\n",o.f2());retu

node.js - 如何销毁 Node 中的firebase ref

如果我在Node中这样做:console.log('1');console.log('2');输出:12过程结束。如果我把它改成这样:console.log('1');varFirebase=require('firebase');varref=newFirebase('https://.firebaseio.com/');console.log('2');输出:12这个过程还在继续。我相信这是因为ref使进程保持活力。我知道我可以使用process.exit但我不想那样做。我实际上不希望进程退出,我只是想确保我的firebaseref不会永远存在内存泄漏问题。完成后有什么方法可以销毁