草庐IT

MYLIB_FUNCTION_ATTRIBUTE

全部标签

c++ - 我们需要 unary_function 和 binary_function 做什么?

我阅读了有关二元和一元函数的教程。我了解它们的结构,但我无法想象在哪种情况下我需要这些功能。你能举个例子来说明它们的用法吗?http://www.cplusplus.com/reference/std/functional/unary_function/http://www.cplusplus.com/reference/std/functional/binary_function/ 最佳答案 这些不是函数,它们是类(实际上是结构,但没关系)。当您定义自己的二进制函数以与STL算法一起使用时,您从这些类派生它们以便自动获取所有类型定

c++ - GCC/VS2008 : Different behaviour of function call when templated base class is derived from itself

以下代码适用于VisualStudio2008,但不适用于GCC/G++4.3.420090804。根据C++标准,哪种行为正确?templatestructA:A{};templatestructA{};structB:A{};templatevoidFunc(constA&a){}intmain(){Aa;//isderivedfromAFunc(a);//vs2008:ok,g++:ok//Comeau:okBb;//isderivedfromAFunc(b);//vs2008:ok,g++:error,nomatchingfunctionforcalltoFunc(B&)//C

c++ - GCC/VS2008 : Different behaviour of function call when templated base class is derived from itself

以下代码适用于VisualStudio2008,但不适用于GCC/G++4.3.420090804。根据C++标准,哪种行为正确?templatestructA:A{};templatestructA{};structB:A{};templatevoidFunc(constA&a){}intmain(){Aa;//isderivedfromAFunc(a);//vs2008:ok,g++:ok//Comeau:okBb;//isderivedfromAFunc(b);//vs2008:ok,g++:error,nomatchingfunctionforcalltoFunc(B&)//C

c++ - 错误 C2733 不允许重载函数 'function' 的第二个 C 链接

我正在尝试在VisualStudio2010pro中编译旧的cppMFC项目。它使用使用Labview编译的dll,我正在添加此信息,因为我不知道是什么导致了错误消息..错误消息显示在多个函数上,所有错误类型都相同。errorC2733:secondClinkageofoverloadedfunction'functionname'notallowed.“函数名”包括:“StrCatW”、“StrCmpNW”、“StrCmpW”、“StrCpyNW”和“StrCpyW”我找到了similarcase在网络上。虽然链接中的建议在我的情况下没有解决,但我仍然看到相同的错误消息。提前感谢任何

c++ - 错误 C2733 不允许重载函数 'function' 的第二个 C 链接

我正在尝试在VisualStudio2010pro中编译旧的cppMFC项目。它使用使用Labview编译的dll,我正在添加此信息,因为我不知道是什么导致了错误消息..错误消息显示在多个函数上,所有错误类型都相同。errorC2733:secondClinkageofoverloadedfunction'functionname'notallowed.“函数名”包括:“StrCatW”、“StrCmpNW”、“StrCmpW”、“StrCpyNW”和“StrCpyW”我找到了similarcase在网络上。虽然链接中的建议在我的情况下没有解决,但我仍然看到相同的错误消息。提前感谢任何

c++ - 为什么 std::bind 可以分配给参数不匹配的 std::function?

我的代码如下:#include#includeusingnamespacestd;voidF(intx){coutf1=std::bind(F,std::placeholders::_1);f1(100);//Thisworks,willprint100.intx=0;std::functionf2=std::bind(F,x);f2();//Thisworks,willprint0.std::functionf3=std::bind(F,x);f3(200);//BUTWHYTHISWORKS??????Itprints0.return0;}我的编译器信息是:AppleLLVM版本6

c++ - 为什么 std::bind 可以分配给参数不匹配的 std::function?

我的代码如下:#include#includeusingnamespacestd;voidF(intx){coutf1=std::bind(F,std::placeholders::_1);f1(100);//Thisworks,willprint100.intx=0;std::functionf2=std::bind(F,x);f2();//Thisworks,willprint0.std::functionf3=std::bind(F,x);f3(200);//BUTWHYTHISWORKS??????Itprints0.return0;}我的编译器信息是:AppleLLVM版本6

c++ - 为什么从 C++11 中删除了 unary_function、binary_function?

我发现binary_function已从C++11中删除。我想知道为什么。C++98:templatestructless:binary_function{booloperator()(constT&x,constT&y)const{returnxC++11:templatestructless{booloperator()(constT&x,constT&y)const{returnx修改-----------------------------------------------------------------------------templatestructunary_fu

c++ - 为什么从 C++11 中删除了 unary_function、binary_function?

我发现binary_function已从C++11中删除。我想知道为什么。C++98:templatestructless:binary_function{booloperator()(constT&x,constT&y)const{returnxC++11:templatestructless{booloperator()(constT&x,constT&y)const{returnx修改-----------------------------------------------------------------------------templatestructunary_fu

c++ - 为什么 std::function 实例有默认构造函数?

这可能是一个哲学问题,但我遇到了以下问题:如果你定义了一个std::function,但你没有正确初始化它,你的应用程序将会崩溃,像这样:typedefstd::functionMyFunctionType;MyFunctionTypemyFunction;myFunction();如果函数作为参数传递,像这样:voidDoSomething(MyFunctionTypemyFunction){myFunction();}然后,当然,它也会崩溃。这意味着我不得不添加这样的检查代码:voidDoSomething(MyFunctionTypemyFunction){if(!myFunct