草庐IT

unary_function

全部标签

c++ - std::function 中的可变模板参数匹配

我有以下代码:#include#includetemplatevoidfunc(std::functionx){}voidf(double){}intmain(){//func(f);//compileerrorhereinthevariadiccasefunc(std::function(f));}我有两个问题:1.我不明白为什么func(f);行给我一个编译错误/Users/vlad/minimal.cpp:10:5:error:nomatchingfunctionforcallto'func'func(f);//compileerrorhereinthevariadiccase^

c++ - 嵌套类奇怪函数查找: surrounding class functions hide global functions

我有以下简化代码namespaceNamespace{intfoo(){return1;}classClass{public:intfoo()const{return2;}classNested{public:Nested(){cout我得到了这个错误:error:cannotcallmemberfunction‘intNamespace::Class::foo()const’withoutobject:cout似乎编译器选择了非静态intNamespace::Class::foo()const而不是全局函数intNamespace::foo()。但是怎么能指望其他类的非静态函数可以在

c++ - 类导出错误(错误 C2470 : looks like a function definition)

我无法导出类:#ifndefSDBIDI#defineSDBIDI#ifndefSDBIDI_FLAG#defineSDBIDI_ORIENT__declspec(dllimport)#else#defineSDBIDI_ORIENT__declspec(dllexport)#endif#include"TCInfoSuVars.h"//classishere!SDBIDI_ORIENTintmyFoo(FILE*file);//exportingfunction#endifTCInfoSuVars.h中的类定义#pragmaonce#include#includeclassSDBID

c++ - 将具有 unique_ptr 参数的函数绑定(bind)到 std::function<void()>

我正在尝试使以下代码工作:#include#include#include#includeusingnamespacestd;classFoo{public:Foo():m_str("foo"){}voidf1(strings1,strings2,unique_ptrp){printf("1:%s%s%s\n",s1.c_str(),s2.c_str(),p->str());}voidf2(strings1,strings2,Foo*p){printf("2:%s%s%s\n",s1.c_str(),s2.c_str(),p->str());}constchar*str()const{

C++0x:在 std::map 中存储任何类型的 std::function

我试图在映射中存储一组std::function(在GCC4.5下)我想要两种东西:存储参数已经传递的函数;那么你就有调用f()存储不带参数的函数;那么你必须打电话f(...)我想我用类命令和管理器实现了第一个:classCommand{std::functionf_;public:Command(){}Command(std::functionf):f_(f){}voidexecute(){if(f_)f_();}};classCommandManager{typedefmapFMap;public:voidadd(stringname,Command*cmd){fmap1.inse

c++ - 警告 : overloaded virtual function "Base::process" is only partially overridden in class "derived"

我低于警告。我的部分代码是:classBase{public:virtualvoidprocess(intx){;};virtualvoidprocess(inta,floatb){;};protected:intpd;floatpb;};classderived:publicBase{public:voidprocess(inta,floatb);}voidderived::process(inta,floatb){pd=a;pb=b;....}我低于警告:Warning:overloadedvirtualfunction"Base::process"isonlypartiallyo

c++ - gcc 和 clang 抛出 "no matching function call"但 msvc (cl) 编译并按预期工作

我写了一个小的函数模板,将不同的容器连接到一个新的容器中:#include#include#include#include#includenamespaceimpl{templatevoidjoin(OutIteratoriterator,constContainer&container,constContainers&...containers){for(constauto&item:container)*iterator++=item;join(iterator,containers...);//gccandclangcannotresolvethiscall}templatevo

c++ - 枚举整数类型转换 : operator or function

在我使用的外部代码中有枚举:enumEn{VALUE_A,VALUE_B,VALUE_C};在我使用的另一个外部代码中有3个#define指令:#defineValA5#defineValB6#defineValC7很多时候我有等于ValA或ValB或ValC的intX,我必须将它转换为En的相应值(ValA到VALUE_A,ValB到VALUEB,等等),因为某些函数签名具有枚举En。而很多时候我不得不做相反的操作,将enumEn翻译成ValA或ValB或ValC。我无法更改这些函数的签名,而且有很多这样的函数。问题是:翻译怎么做?我应该创建2个将被隐式使用的转换运算符吗?或者我应该

c++ - 如何摆脱这个错误 : "MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup"

我正在帮助一位friend学习C++,但老实说,我们需要很大的帮助。为什么我们总是得到这个错误:“MSVCRTD.lib(crtexe.obj):errorLNK2019:unresolvedexternal符号main在函数__tmainCRTStartup中引用”代码如下://MariaDelgado(1013725)-Coursework2-ProgramConductingtimbercomponentstructuraldesign#include#include#include#include#includeusingnamespacestd;//VariablesforS

c++ - "Unresolved overloaded function type"尝试将 for_each 与 C++ 中的迭代器和函数一起使用时

//for(unsignedinti=0;i我正在尝试使用for_each循环代替for循环进行赋值。我不确定为什么会收到此错误消息:Infunctionâvoidclean_entry(conststd::string&,std::string&)â:prog4.cc:62:40:error:nomatchingfunctionforcalltoâfor_each(std::basic_string::iterator,std::basic_string::iterator,)â 最佳答案 写:for_each(c.begin()