草庐IT

member-functions

全部标签

c++ - 如何将成员函数指针传递给采用常规函数指针的函数?

我有一个播放器类,看起来像这样(精简到这个问题所需的内容):classPlayer{public:Player();~Player();voidkill();voiddeath();voidreset();};kill()、death()和reset()函数如下所示:voidPlayer::kill(){void(*dPtr)()=&death;Game::idle(dPtr,48);}voidPlayer::death(){reset();}voidPlayer::reset(){//resets}idle函数是Game的一个静态成员函数,它接受一个函数指针和一个整数n,并在ntic

c++ - 错误 : no matching function for call to ‘to_string(std::basic_string<char>&)’

即使在模板中我可以有任何类型,函数to_string对基本字符串不起作用:例如:std::stringstr("mystring");my_class(str);用这个仿函数定义:templatevoidoperator()(valuetypevalue){...private_string_field=std::to_string(value);不起作用。这是错误:error:nomatchingfunctionforcallto‘to_string(std::basic_string&)’避免它的最佳方法是什么。事先,我要求避免仅仅因为一些常见的关键字就链接到不相关的问题。

c++ - "no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’“

我正在尝试使用std::async创建线程,但我不断收到错误“没有匹配函数调用‘async(std::launch,,std::string&)’”在行上ConnectFuture=std::async(std::launch::async,Connect_T,ip);这是产生这种行为的代码:#includeclasslibWrapper{public:voidConnect(std::stringip);voidConnect_T(std::stringip);private:std::futureConnectFuture;};voidlibWrapper::Connect(std

c++ - std::function 签名指针 vs 指针引用 = 没有区别?

这是代码示例:#include#includestructFoo{};typedefboolfunc_type(Foo*&,conststd::string&);typedefstd::functionFunctionalType;boolf(Foo*,conststd::string&){}intmain(){#if1func_type*func;func=f;#elseFunctionalTypef2;f2=f;#endif}如您所见,我已将“对指针的引用”声明为第一个参数的函数类型Foo*&,我希望该函数仅以“指针”作为第一个参数Foo*不能分配给这种类型的变量。#if1regi

c++ - 错误 : imread is not a member of cv

我使用OpenCV3.0和Ubuntu14.04。我正在尝试使用opencv在ubuntu上编译一些代码。我收到错误"error:'imread'isnotamemberof'cv'"由于我以前的搜索知识,我尝试通过添加“highgui.h”进行编译。我使用:$g++main.cppHOG.cppHOGFeaturesOfBlock.cpp-I/usr/local/include/opencv-lml-lcvaux-highgui-lcv-lcxcore-ofeatureExtractor在终端上编译。有什么建议吗?问候。可以。 最佳答案

c++ - 使用 std::function 或转发引用作为高阶函数的通用可调用对象输入参数?

我想知道编写一个以std::function作为输入参数的高阶函数的主要区别、优缺点。或转发引用,例如templatevoidhof(F&&fun);.显然,前者比后者更严格,因为它指定了输入可调用对象必须符合的函数类型。 最佳答案 std::function通常具有显着的运行时开销。通过template参数传递通用可调用对象可避免std::function的间接成本,并允许编译器积极优化。我在theendofthisarticle为lambda递归编写了一些简单的基准测试(Y组合器与std::function).std::func

c++ - 模板实例化失败 : compiler choosing improper overload function

我对模板并不陌生,但我遇到了一个相当奇怪的问题,我需要将模板类型分离到它的组件中,以用于我正在处理的数据序列化程序。这很难解释,所以我已经证明了。这是我简化的示例问题,example.cpp。templatevoidfoo(T&arg){}templatevoidfoo(T&arg){}intmain(intargc,char*argv[]){foo(argc);return0;}我得到一个错误,然后是一个警告,这似乎表明它正在尝试实例化两个函数,但只有其中一个是合适的。$g++-Wall-Wexample.cppexample.cpp:2:43:error:‘T’isnotatemp

c++ - syntax::function_name 在 C++ 中是什么意思?

在名为::foo()的函数中,我不明白语法的用途。如果它是foo::count_all()那么我知道count_all是类或命名空间foo的函数。在::foo()的情况下,::引用的是什么? 最佳答案 ::运算符正在调用namespace或class。在您的情况下,它正在调用全局命名空间,它是不在命名空间中的所有内容。下面的例子说明了为什么namespace很重要。如果您只是调用foo(),您的调用将无法解析,因为有2个foo。您需要使用::foo()解决全局问题。namespaceHidden{intfoo();}intfoo()

c++ - 错误 : no matching member function for call to 'push_back'

为什么我在最后两行收到错误?目标是在集合中找到对象,并修改其内容。usingnamespacestd;structmystruct{intid;vectory;mystruct(constintid):id(id){}booloperatorsx;mystructx(1);x.y.push_back(1);x.y.push_back(2);sx.insert(x);//set::iteratori=sx.find(1);constmystruct*x1=&(*i);constmystructx2=*x1;couty)y)y.push_back(4);}好像迭代器返回的是常量对象,不让我

c++ - 错误 : no matching function for call to . .. 在返回语句

我在openSUSELeap15上的Qt5.9.4上使用GCC7。我有以下类(class):classManSuppProps:publicQObject{Q_OBJECTpublic:explicitManSuppProps(QStringparentName);explicitManSuppProps(){}explicitManSuppProps(constManSuppProps&manSuppProps);explicitManSuppProps(ManSuppProps&manSuppProps);~ManSuppProps();private:QVector3Dm_sup