草庐IT

override_function

全部标签

c++ - 编译时出现错误 "fopen' : This function or variable may be unsafe.

这个问题在这里已经有了答案:fopendeprecatedwarning(10个回答)关闭8年前。编译时收到此错误:'fopen':Thisfunctionorvariablemaybeunsafe.Considerusingfopen_sinstead.Todisabledeprecation,use_CRT_SECURE_NO_WARNINGS.我是C++新手并打开CV,因此请帮助我摆脱这个错误。谢谢void_setDestination(constchar*name){if(name==NULL){stream=stdout;}else{stream=fopen(name,"w"

c++ - std::function<void(int&)> 类型的大小

std::function有什么魔力?从C++11开始,它的sizeof=32?如果我将函数引用存储为指针,则只需8bytes(在64位机器上)。 最佳答案 对于std::function这是对象大小和分配之间的权衡,这很有趣:对于小型函数对象,最好避免分配。另一方面,这样做会增加对象的大小。为了使小函数优化有用并且在实际调用对象时不引入开销,对象大小需要至少为两个指针加上一些内存来存储简单的函数对象。似乎32字节的大小正是这个(在sizeof(T*)为8的系统上)。也就是说,内部是std::function对象存储继承层次结构:基

c++ - 获取 std::function 的名称

在下面的玩具示例中,我想获取一个函数的名称。函数本身作为std::function参数给出。是否可以在C++中获取std::function对象的名称?voidprintName(std::functionfunc){//Needafunctionname()std::cout否则我将不得不将函数的名称作为第二个参数。 最佳答案 不,没有。函数名(如变量名)被编译出来,因此它们在运行时不可见。最好的办法是按照您自己的建议传递函数的名称(使用std::string或constchar*)。(或者,您可以基于C++11中引入的__fun

c++ - 将 boost::function 降级为普通函数指针

想要将boost::bind传递给需要普通函数指针(相同签名)的方法。typedefvoidTriggerProc_type(Variable*,void*);voidInitVariable(TriggerProc_type*proc);boost::functiontriggerProc...InitVariable(triggerProc);errorC2664:'InitVariable':cannotconvertparameter1from'boost::function'to'void(__cdecl*)(type*,void*)'我可以避免存储boost::functi

c++ - 为什么使用 'function address == NULL' 而不是 'false' ?

浏览一些遗留代码我发现了这样的功能:staticinlineboolEmptyFunc(){return(void*)EmptyFunc==NULL;}和这个有什么区别:staticinlineboolEmptyFunc(){returnfalse;}创建此代码是为了在几个不同的平台下编译,例如PS2、Wii、PC...有什么理由使用第一个函数吗?喜欢更好的优化或避免一些奇怪的编译器错误行为? 最佳答案 两个函数在语义上是相同的:它们总是返回false*。标准完全允许将第一个表达式折叠为常数值“false”,因为它不会改变任何可观察

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

c++ - Fast Delegate (et al) 背后的想法是否已用于优化 std::function?

已经有C++“委托(delegate)”的提议,其开销低于boost::function:MemberFunctionPointersandtheFastestPossibleC++DelegatesFastC++DelegateTheImpossiblyFastC++Delegates有没有使用这些想法来实现std::function,从而获得比boost::function更好的性能?有没有人比较std::function与boost::function的性能?我想专门了解英特尔64位架构上的GCC编译器和libstdc++,但欢迎提供有关其他编译器(例如Clang)的信息。

c++ - 类继承 : Function is inaccessible

我收到此错误,但我认为只有在成员(member)的保护级别太高且无法访问时才会收到此错误,但我还是收到了。Shopable.h:#ifndef_SHOPABLE_H_#define_SHOPABLE_H_#include"Library.h"classShopable{private:std::stringName;intCost;std::stringDescription;public:std::stringgetName()const{returnName;}intgetCost()const{returnCost;}virtualstd::stringgetDesc()cons

c++ - 是否有 eval ("function(arg1, arg2)"的 C/C++ 等价物?

它需要一种调用函数的方法,该函数的名称存储在类似于eval的字符串中。你能帮我吗? 最佳答案 C++没有反射,所以你必须破解它,即。e.:#include#include#include#includevoidfoo(){std::cout>functions;functions["foo"]=foo;functions["boo"]=boo;functions["too"]=too;functions["goo"]=goo;std::stringfunc;std::cin>>func;if(functions.find(func)

javascript - 使用 Cheerio 和 jsonframe 抓取时,获取 TypeError : selector. includes is not a function

我正在尝试使用以下代码废弃网站:constcheerio=require('cheerio');constjsonframe=require('jsonframe-cheerio');const$=cheerio.load('https://coinmarketcap.com/all/views/all/');jsonframe($);//initializestheplugin//exceptionhandlingprocess.on('uncaughtException',err=>console.error('uncaughtexception:',err))process.on