草庐IT

function-args

全部标签

c++ - 具有与 std::function 不同签名的 Lambda 函数

我不明白为什么第三种情况没问题(即使lambda的参数类型不同于std::function类型)而编译器却提示第四种情况:functionidInt=[](inti){returni;};//OKfunctionidInt=[](int&i){returni;};//OKfunctionidInt=[](inti){returni;};//OKfunctionidInt=[](int&i){returni;};//ERROR! 最佳答案 当你写的时候:functionidInt=[](int&i){returni;};//ERROR

C++ - 错误 E2285 : Could not find a match for 'tolower(char *)' in function parseInput(fstream &)

给定以下代码:voidparseInput(fstream&inputFile){constintLENGTH=81;charline[LENGTH];while(!inputFile.fail()){inputFile.getline(line,LENGTH);line=tolower(line);cout编译时出现这个错误:ErrorE2285:Couldnotfindamatchfor'tolower(char*)'infunctionparseInput(fstream&)我知道它返回一个int,而不是int[],这是否意味着我不应该使用getline而应该将输入字符转换为字符

c++ - 为什么隐含的 "lambda to function pointer conversion"禁止静态成员的 "by reference"捕获?

C++11标准说(或者至少,我拥有的版本——不是最终版本):Theclosuretypeforalambda-expressionwithnolambda-capturehasapublicnon-virtualnon-explicitconstconversionfunctiontopointertofunctionhavingthesameparameterandreturntypesastheclosuretype’sfunctioncalloperator.我理解为什么无法从有状态lambda中获取函数指针,因为函数指针本身不能保存任何数据。但是当捕获的对象只是一个静态成员/静

c++ - 无法从模板类调用通用 std::function 成员

编译以下代码时:#includetemplateclassClass{std::functionfunc;public:Class(conststd::function&arg):func(arg){}voidcallFunc(){func();}};voidf(constinti){}intmain(){Classa(std::bind(f,10));a.callFunc();return0;}VS2015编译器在第六行生成以下错误消息:errorC2064:termdoesnotevaluatetoafunctiontaking0arguments.现在,我相信这是因为编译器认为f

c++ - 创建具有有限参数的 std::function 类型

给定可调用函数的类型C,我想在编译时得到一个std::function;其中的类型:具有与函数相同的返回类型C参数类型是第一个N函数的参数类型C这意味着,对于给定的类型void(int,char,double)和给定的N,函数的类型是:N=1=>结果类型:std::functionN=2=>结果类型:std::functionN=3=>结果类型:std::functionN>3=>编译时错误例子:templateconstexprautoget(){return/*(magicallysomehow)*/std::function}templatestructS{usingfunc=d

c++ - "Expected ' (' for function-style cast or type construction"错误是什么意思?

我收到错误“Expected'('forfunction-stylecastortypeconstruction”,我已尽力在线研究此错误的含义,但无法找到导致此错误的任何文档错误。我在StackOverflow上发现的所有相关问题都修复了特定的代码片段,并且没有更笼统地解释导致错误的原因。这些包括Expected'('forfunction-stylecastortypeconstruction答案突出了代码的几个问题。究竟是哪个问题导致了错误尚不清楚。c++Xcodeexpected'('forfunction-stylecastortypeconstruction在主函数中定义函

c++ - 在调用过程中删除 std::function

在调用过程中销毁/删除std::function是否是未定义行为?classEvent{public:Event(std::functionf):func(std::move(f)){}~Event(){}std::functionfunc;};intmain(){std::vectorevents;autofunc=[&](){events.pop_back();std::cout 最佳答案 这未被[res.on.objects]p2定义:Ifanobjectofastandardlibrarytypeisaccessed,and

c++ - 比较 std::function<>

是否有可能以某种方式比较两个std::tr1::function对象?如果我有一个function的集合怎么办?对象并想添加和删除事件处理程序?添加是微不足道的,但要找到要删除的那个似乎是不可能的。 最佳答案 简单来说,做不到。std::function(在它的所有迭代中,包括boost::function和std::tr1::function)不支持运算符==。 关于c++-比较std::function,我们在StackOverflow上找到一个类似的问题:

c++ - 在 C++ 中处理 va_args

我有一个函数A(...)和B(...)。现在我必须在A中调用B,任何将...从A传递到的方法>B?伪代码:voidA(...){//SomeoperatorsB(...);//Insteadof...IneedtopassA'sargs}附注我知道这可以使用宏来完成,但是函数呢。 最佳答案 您不能转发va_args。您只能转发va_list。voidvB(intfirst,va_listap){//dostuffwithap.}voidB(intfirst,...){va_listap;va_start(ap,first);vB(f

c++ - *v8::String::Utf8Value(args[0]->ToString()) 不返回 node.js 插件参数的字符串

我发现*v8::String::Utf8Value(args[0]->ToString())在Node0.8.232位上返回正确的字符串,但在Node0.8上不返回正确的字符串。8个64位。有人知道为什么吗?我的node.js插件看起来像这样:#defineBUILDING_NODE_EXTENSION#include#defineMAX_OUTPUT_BUF80extern"C"char*do_sqlsig(char*in);usingnamespacev8;HandleSqlsig(constArguments&args){HandleScopescope;char*c_arg,*