草庐IT

FUNCTION_NAME

全部标签

c++ - 错误 : Expected template-name before '<' token

我正在尝试编译一个实现chain和chainNodes的程序并在以下行(第22行)出现错误:classchain:publiclinearList错误是:Error:expectedtemplate-namebefore'知道为什么会出现这种情况吗?我的代码如下://linkedimplementationofalinearlist//derivesfromabstractclasslinearListjusttomakesure//allmethodsoftheADTareimplemented#ifndefchain_#definechain_#include#include#in

c++ - 使用 float 给出 "call to overloaded function is ambiguous"错误

这个问题在这里已经有了答案:Referencetofunctionisambiguous[duplicate](2个答案)关闭6年前。我正在重载函数add(),但是当我使用float数据类型时它显示错误。但是,当我将其更改为double时,它工作正常。为什么float会导致错误?代码是:#includeusingnamespacestd;classstudents{private:inti;floatf;public:voidadd(intb){i=b;cout错误:Infunction'intmain()':[Error]callofoverloaded'add(double)'is

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++ - 多次调用 typeid(T).name() 会返回同一个指针吗?

在C++中,我可以使用typeid运算符来检索任何多态类的名称:constchar*name=typeid(CMyClass).name();返回的constchar*指向的字符串willbeavailabletomyprogramforaslongasthecorrespondingclassexists.typeid(T).name()的多次调用是否会为相同的classT返回相同的指针值,或者它们是否允许返回不同的指针? 最佳答案 不,它们不需要返回相同的指针。我在野外系统也看到过没有。每个DLL都有自己的包含nmae的类型对象

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