草庐IT

C_Func_using_Func_ptr

全部标签

ElasticSearch--warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME

es和jdk是一个强依赖的关系,所以当我们在新版本的ElasticSearch压缩包中包含有自带的jdk,但是当我们的Linux中已经安装了jdk之后,就会发现启动es的时候优先去找的是Linux中已经装好的jdk,此时如果jdk的版本不一致,就会造成jdk不能正常运行,报错如下:warning:usageofJAVA_HOMEisdeprecated,useES_JAVA_HOMEFutureversionsofElasticsearchwillrequireJava11;yourJavaversionfrom[/usr/local/jdk1.8.0_291/jre]doesnotmeett

c++ - 使用 unique_ptr 进行依赖注入(inject)以模拟

我有一个使用Bar类的Foo类。Bar仅在Foo中使用,而Foo正在管理Bar,因此我使用unique_ptr(不是引用,因为我不需要Foo之外的Bar):usingnamespacestd;structIBar{virtual~IBar()=default;virtualvoidDoSth()=0;};structBar:publicIBar{voidDoSth()override{coutbar):bar_(std::move(bar)){}voidDoIt(){bar_->DoSth();}private:unique_ptrbar_;};目前一切顺利,一切正常。但是,当我想对代

c++ - 带有 C++ 模板的虚假 "use of local variable with automatic storage from containing function"?

以下代码无法在g++7.2.0中编译templateclassRequest{intcontent=0;public:friendvoidsetContent(inti,void*voidptr){Request*ptr=(Request*)voidptr;ptr->content=i;}intgetContent(){returncontent;}};intmain(){Requestreq;setContent(4,&req);returnreq.getContent();}有错误test.cpp:Ininstantiationof‘voidsetContent(int,void*

c++ - shared_ptr 原子函数采用指针而不是引用的基本原理

如你所见here,shared_ptr作为指针而不是引用传递。还要注意Allthesefunctionsinvokeundefinedbehaviorifpisanullpointer.那么为什么是指针呢?我认为在C++中,应该优先使用引用,除非有特定的原因需要使用指针。 最佳答案 templateboolatomic_is_lock_free(conststd::shared_ptr*p);接受一个指向智能指针的指针,因为这是更通用的atomic_is_lock_free的特例:templateboolatomic_is_lock

c++ - 有没有办法更改现有 shared_ptr 实例的删除操作

我有一个函数,我希望在90%的时间内完成清理操作,但在10%的时间内我希望完成一些其他操作。有什么方法可以使用一些标准范围的控件,例如shared_ptr这样一开始它可以有一个删除操作,然后在函数中可以更改删除操作?shared_ptrptr(newT,std::mem_fun_ref(&T::deleteMe));ptr.pn.d=std::mem_fun_ref(&T::queueMe); 最佳答案 不是真的-shared_ptr的标准以这样的方式编写Deleter可以按值存储在控制节点(一个包含引用计数器、保存删除器、跟踪弱指

c++ - 为什么即使给定了模板参数,ptr_fun 也会发现这种模棱两可的情况?

所以,这里有一些基本代码可以说明我的问题:#includeintfunc(intx){returnx;}intfunc(intx,inty){returnx+y;}intmain(){std::ptr_fun(func);}对于具有不同数量参数的函数,我们有2个重载。然后我尝试在仿函数中转换单参数版本。当然,我遇到了以下错误:test.cc:Infunction'intmain()':test.cc:13:29:error:callofoverloaded'ptr_fun()'isambiguous/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/inclu

c++ - 这两个来源之间是否存在关于 `auto_ptr` 模板类的矛盾?

这site关于“所有权、来源和汇”的陈述:“当您复制auto_ptr时,您会自动将所有权从源auto_ptr转移到目标auto_ptr;如果目标auto_ptr已经拥有一个对象,则该对象首先被释放。复制后,只有目标auto_ptr拥有该指针,并会在适当的时候将其删除,而源将设置回空状态,不能再用于引用拥有的对象。".现在考虑operator=()的定义对于templacteclassauto_ptr,在Stroustrup的TheC++ProgrammingLanguageThirdEdition第14章第368页中:auto_ptr&operator=(auto_ptr&a)thro

c++ - 错误 : use of undeclared identifier 'ctime_s'

当我尝试使用ctime_s编译cpp代码时,使用了未声明的标识符“ctime_s”。我该如何解决?主要.cpp#include#includeintmain(intargc,constchar*argv[]){//insertcodehere...std::cout结果Machida-no-MacBook-Air:KnowledgeBasemachidahiroaki$gccmain.cpp--verboseAppleLLVMversion6.1.0(clang-602.0.49)(basedonLLVM3.6.0svn)Target:x86_64-apple-darwin14.1.0

c++ - 使用 braced-init 初始化 std::shared_ptr<std::map<>>

我有以下shared_ptr到map:std::shared_ptr>我想使用braced-init来初始化它。可能吗?我试过:std::strings1("temp");std::shared_ptr>foo=std::make_shared>(1000.0,s1);但是在使用Xcode6.3编译时出现以下错误:/usr/include/c++/v1/map:853:14:Candidateconstructornotviable:noknownconversionfrom'double'to'constkey_compare'(aka'conststd::__1::less')fo

c++ - 如何为 std::shared_ptr<PureVirtualClass> 传递默认参数

我有一个类型的函数virtualvoidfoo(bla,bla,bla,std::shared_ptrlogger)=0;我想传递一个带有NULL指针的默认参数,例如:virtualvoidfoo(bla,bla,bla,std::shared_ptrlogger=NULL)=0;所以在实现中,如果logger是NULL我什么也不做,否则我使用logger。我试图寻找解决方案但找不到..UPD:重复声明无关紧要,我问的是默认NULL参数。有没有可能gcc4.4不支持nullptr? 最佳答案 你可以简单地这样做:virtualvoi