草庐IT

c++ - 铛++ : error: call to 'partition' is ambiguous

#include#includetemplateBidirectionalIteratorpartition(BidirectionalIteratorfirst,BidirectionalIteratorlast,UnaryPredicatepred){while(first!=last){while(pred(*first)){++first;if(first==last)returnfirst;}do{--last;if(first==last)returnfirst;}while(!pred(*last));std::swap(*first,*last);++first;}re

c++ - std::call_once,应该什么时候用?

std::call_oncefunction,在C++11中引入,确保可调用对象以线程安全的方式被恰好调用一次。因为这可以通过其他方式实现-什么时候应该使用std::call_once?它旨在解决什么类型的问题?请举例说明。 最佳答案 示例:我将它用于libcURL从网站检索http(s)数据。在libcURL中,您必须执行one-timeglobalinitialization在你能够使用图书馆之前。鉴于初始化是不是线程安全的,但从网站请求数据是线程安全的,我使用call_once只调用我的初始化一次,无论在什么线程中以及是否它被

c++ - 调试断言失败表达式 : _pFirstBlock == pHead using OpenCV and C++ trying to call SurfFeatureDetector

我在使用OpenCV的C++中有这个函数:vectortest(Matimg){intminHessian=400;SurfFeatureDetectordetector(minHessian);vectorvKeypoints;detector.detect(img,vKeypoints);returnvKeypoints;}当我在主方法中调用此函数时,一切正常。intmain(int,char**argv){//pathtoaimage-filechar*input="image.jpg";//readimageintoMatimgMatimg=imread(input,CV_LO

c# - C++ Interop : How do I call a C# class from native C++, 类是非静态的吗?

我有一个用nativeC++编写的大型应用程序。我还有一个C#类需要调用。如果C#类是静态的,那将是微不足道的(网络上有很多示例)-只需编写混合的C++/CLI包装器,导出接口(interface),即可完成。但是,C#类是非静态的,并且不能更改为静态的,因为它有一个接口(interface)(如果您试图将C#类设为静态,编译器将生成错误)。以前有没有人遇到过这个问题-如何将非静态C#类导出到nativeC++?更新2010-11-09最终解决方案:尝试使用COM,效果很好,但不支持结构。所以,我选择了C++/CLI包装器,因为我绝对需要能够在C++和C#之间传递结构。我根据此处的代码

c++ - 并发 std::call_once 调用

有人能解释一下为什么这个程序中的两个线程(当使用VisualStudio2012/2013附带的编译器编译时)在两个std::call_once调用都被执行之前被阻塞吗?另一个VisualStudio错误(如果使用GCC编译时它的行为符合预期)?有人可以提出解决方法吗?想象一下我为缩小问题范围所经历的所有痛苦,请大发慈悲。#include#include#include#includenamespace{std::once_flagdid_nothing;voiddo_nothing(){}voidsleep_shorter_and_do_nothing_once(){std::thi

c++ - 为什么 boost::call_traits<T>::param_type 是枚举类型的引用?

基本的C++03枚举类型只是一个具有奇特名称的整数值,因此我希望按值传递它....出于这个原因,我还期望boost::call_traits::param_type与T=SomeEnum确定最有效的传球方式T是按值(value)。从boost文档中查看CallTraits:Definesatypethatrepresentsthe"best"waytopassaparameteroftypeTtoafunction.当我使用boost::call_traits::param_type时与T=SomeEnum它确定SomeEnum应该通过引用传递。我也期待C++11classenums也

c++ - 视觉口齿不清 : how to call functions in external C++ DLL

我有一个我编写的C++dll(native,而不是.net),我想使用VisualLisp的功能。任何人都可以指出如何执行此操作的示例,或者至少要阅读哪部分文档吗? 最佳答案 我通过为我的dll编写一个activex/COM包装器解决了这个问题,我认为这应该使将来更容易链接。在theswamp上开始一个线程从好人那里得到了一些关于如何从VisualLisp调用COM的答案。作为记录,它看起来像这样://inc++...(headerandIDLfilealsoneeded)hresulttimestwo(doublein,doubl

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++ - c++ : error: must use '.*' or '->*' to call pointer-to-member function in function 中的函数指针

代码片段如下。无法理解为什么会出现此错误。voidSipObj::check_each_field(){map::iteratormsg;stringstr;charname[20];boolres=false;sscanf(get_payload(),"%s%*s",name);LOGINFO(lc())second;res=(this).*sip_field();}}typedefbool(SipObj::*sip_field_getter)();staticmapsip_field_map;sip_field_getter是函数名的占位符 最佳答案

c++ - 尝试包装函数返回值时出现 "<class name> does not provide a call operator"错误

我正在尝试编写一个函数,它将一个仿函数作为参数,调用仿函数,然后返回它的返回值,并将其包装在boost::shared_ptr中。以下拒绝编译,我完全没有想法。我得到“std::vector不提供调用操作符”(大致)。我在MacOSX上使用Clang3.1。templateboost::shared_ptrReturnValueAsShared(boost::functionfunc){returnboost::make_shared(func());}这是我尝试使用它的上下文:make_shared>>>(bind(ReturnValueAsShared>,bind([afuncti