草庐IT

some_function_returning_an_option

全部标签

c++ - std::binary_function - 调用不匹配?

包括#includeusingnamespacestd;intmain(){binary_functionoperations[]={plus(),minus(),multiplies(),divides()};doublea,b;intchoice;cout>a>>b;cout>choice;cout我得到的错误是:Calcy.cpp:Infunction‘intmain()’:Calcy.cpp:17:error:nomatchforcallto‘(std::binary_function)(double&,double&)’谁能解释为什么我会收到此错误以及如何消除它?

C++ 模板和 "no matching function to call"

我遇到了一个奇怪的错误。我有以下签名的功能:templatestaticboolConvertCbYCrYToRGB(constCharacteristicspace,constDATA*input,DATA*output,constintpixels){后来这样称呼:casekByte:returnConvertCbYCrYToRGB(space,(constU8*)input,(U8*)output,pixels);casekWord:returnConvertCbYCrYToRGB(space,(constU16*)input,(U16*)output,pixels);casek

c++ - boost::program_options:如何获取应用程序名称?

使用BoostProgramOptions,如何获得argv[0]的字符串等价物? 最佳答案 我认为这是不可能的。这可能是因为程序名称也可以合法地用作选项名称。命令行解析器代码明确跳过相关的argv成员:templatebasic_command_line_parser::basic_command_line_parser(intargc,charT*argv[]):detail::cmdline(//Explicittemplateargumentsarerequiredbygcc3.3.1//(atleastmingwversi

c++ - 如何使用 lambda 在 std::function 参数中推导模板类型?

我有一个boost::variant并且我只想在变体是特殊类型时才执行一个仿函数,所以我编写了这个函数:templatevoidif_init(Variant&opt_variant,std::functionfunctor){if(auto*ptr=boost::get(&opt_variant)){functor(*ptr);}}这很好用,但我希望推导出类型T,这样我就可以这样写:if_init(b,[](doublevar){std::cout但是没有推导出类型:type_inference.cpp:19:5:error:nomatchingfunctionforcallto'i

c++ - 将抽象仿函数分配给 std::function - 为什么 std::ref 是一个解决方案?

我想将仿函数对std::function的赋值封装到一个方法中。我必须传递从通用抽象类Slot继承的仿函数,而不是传递std::function或指向std::function的指针(即这些槽提供额外的功能)。我以不同的形式偶然发现了这个问题here.例如。在那里,使用通用槽指针而不是std:functions的动机是仿函数的生命周期管理。下面的代码说明了这个问题。请参阅assignFunctorPtr(...)方法。#include#includetemplateclassSlot;templateclassSlot{public:typedefRRet_type;public:vi

C# 应用程序调用 C++ 方法,错误 : PInvoke: Cannot return variants

我正在尝试弄清楚如何将复杂对象从C++dll返回到调用C#应用程序。我有一个简单的方法,它返回一个工作正常的int。谁能告诉我我做错了什么?C#应用程序:classProgram{staticvoidMain(string[]args){//Erroronthisline:"PInvoke:Cannotreturnvariants"vartoken=LexerInterop.next_token();}}C#LexerInterop代码:publicclassLexerInterop{[DllImport("Lexer.dll")]publicstaticexternobjectnex

c++ - 该程序在 main() 上的 'return;' 之后需要很长时间才能关闭

这是我正在处理的代码:#include#includeusingnamespacestd;staticunsignedlongcollatzLength(unsignedlongn){staticstd::mapcollatzMap;intmapResult=collatzMap[n];if(mapResult!=0)returnmapResult;if(n==1){return1;}else{collatzMap[n]=1+collatzLength(n%2==0?n/2:3*n+1);returncollatzMap[n];}}intmain(){intmaxIndex=1;uns

c++ - 显式默认和删除的构造函数 : is there any similar functionality available in VS2012?

在VS2012中,“显式默认和删除特殊成员函数”功能(http://en.wikipedia.org/wiki/C++0x#Explicitly_defaulted_and_deleted_special_member_functions、http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm)尚不可用(http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx)。是否有任何解决方法来使用此类功能,即使非常冗长?在实践中,我可以翻译这个吗struc

c++ - 错误 : no instance of overloaded function "std::make_shared" matches the argument list

查看ApreviousstackQuestionstd:make_sharedvsstd::shared_ptr,我试图在一个uni项目中实现它。这是之前的“问题”:Ican'tthinkofanysituationwherestd::shared_ptrobj(newObject("foo",1));wouldbepreferredtoautoobj=std::make_shared("foo",1);因此我采用了这段代码:std::shared_ptrpT1(newTriangle(pCanvas,30,30,30,60,60,30,255,0,0));并将其修改为这段代码:aut

c++ - 使用尽可能少的代码将非静态方法包装到带有 "this"参数绑定(bind)的 std::function

这是我正在尝试做的事情:templateclassCSignal{public:voidconnect(std::functiontarget){m_connections.emplace_back(target);}private:mutablestd::vector>m_connections;};connect非常适合静态方法或全局函数。现在,如果我想传递一个成员方法怎么办?看来这是我唯一的选择:structMyStruct{voidprint(floata,intb){std::cout如果我不必指定非常麻烦的占位符,它会适合我。所以我尝试另一种方法。我为成员方法添加了一个新的