草庐IT

implicit-function-declaration

全部标签

c++ - 右值引用 : Why aren't rvalues implicitly moved?

在关于C++右值引用(http://www.artima.com/cppsource/rvalue.html)的Artima文章中有这样的话:这就是为什么在向下传递到基类时必须说move(x)而不是只说x的原因。这是移动语义的一个关键安全特性,旨在防止从某个命名变量意外移动两次。我想不出这样的双招可以执行的情况。你能举个例子吗?换句话说,如果T&&的所有成员都是右值引用而不仅仅是引用,会出现什么问题? 最佳答案 考虑这个场景:voidfoo(std::stringx){}voidbar(std::stringy){}voidtest

C++ "was not declared in this scope"编译错误

C++新手。在我编写的以下程序中出现此错误:g++-oBlobblob.ccblob.cc:Infunction'intnonrecursivecountcells(color(*)[7],int,int)':blob.cc:41:error:'grid'wasnotdeclaredinthisscope代码如下:#includeenumcolor{BACKGROUND,ABNORMAL,TEMPORARY};constintROW_SIZE=7;constintCOL_SIZE=7;intnonrecursivecountcells(color[ROW_SIZE][COL_SIZE]

c++ - 使用参数包将 lambda 转换为 std::function

关于将lambda转换为std::function的SO有几个问题s,但我还没有看到一个使用参数包作为参数列表的。这在我的g++(7.1.1-4)版本上似乎已损坏,可能只是不受支持。那么这是合法的c++17(按照标准)吗?如果不是,为什么?#includetemplatevoidFunctor(std::functionf){}intmain(intargc,char*argv[]){autox=[](inta,intb){returna*b;};Functor(x);return0;}上面的代码无法编译,因为它没有通过类型推导。显然明确输入x作为std::function而不是使用a

c++ - 在 std::function 中存储不可复制但可移动的对象

假设我有一个不可复制但可移动的仿函数s,我如何将它存储在std::function中?即,如何编译以下代码?(使用gcc4.6)#include#includestructS{S()=default;S(Sconst&)=delete;S&operator=(Sconst&)=delete;S(S&&){}voidoperator()(){}};std::functionfunc;voidmake_func(){Ss;func=std::bind(std::move(s));//Thiswon'tcompile}intmain(){make_func();}

C++ 错误 : object of abstract class type is not allowed: pure virtual function has no overrider

继承有问题。我不知道我做错了什么。FigureGeometry.h#ifndefFIGUREGEOMETRY#defineFIGUREGEOMETRYstaticconstfloatPI=3.14159f;classFigureGeometry{public:virtualfloatgetArea()const=0;virtualfloatgetPerimeter()const=0;};#endifCircle.h#ifndefCIRCLE#defineCIRCLE#include"FigureGeometry.h"classCircle:publicFigureGeometry{fl

c++ - Visual Studio 2010 和 std::function

我有这个代码:#include#includestructA{intoperator()(inti)const{std::coutf=std::tr1::ref(a);std::cout目的是通过reference_wrapper传递仿函数对象,以避免无用的复制构造函数调用。我期望以下输出:F:67它可以与GCC>=4.4.0、VisualStudio2008以及通过将std::tr1命名空间替换为boost的boost一起正常工作。它仅不适用于新的VisualStudio2010ExpressBeta2和ReleaseCandidate。这个新的C++特性在vs2010中有问题吗?或

c++ - friend 类概念如何不需要前向声明(forward declaration)?

我最近刚刚了解了C++中的friendclass概念(我用google搜索了一下,但是这个answer让我笑了起来,直到我想起了最重要的部分),并且我正在尝试将它合并到我现在正在进行的项目中。最后挑出了简洁的问题,但总的来说,我对工作代码中完全没有前向声明感到困惑。我所有的类(class)都通过(子)文件夹分开,每个类(class)都分为一个单独的.h和.cpp文件,但这应该足以获得一个对依赖的感觉://FE.h-noimplementations-no.cppfileclassFE{private:virtualvoidsomePrivateFunc()=0;//90%virtual

c++ - 无法使用统一初始化复制 std::vector<std::function<void ()>>。这个对吗?

以下代码无法在GCC4.7.2或Clang3.2中编译:#include#includeintmain(){std::vector>a;std::vector>b{a};}问题是编译器将尝试使用initializer_list创建b,而显然它应该只是调用复制构造函数。然而,这似乎是期望的行为,因为标准规定initializer_list构造函数应该优先。此代码适用于其他std::vector,但对于std::function,编译器无法知道您是否需要initializer_list构造函数或其他构造函数。似乎没有办法绕过它,如果是这种情况,那么您永远不能在模板代码中使用统一初始化。这将

c++ - std::function 与原始函数指针和 void* this 相比的性能?

库代码:classResource{public:typedefvoid(*func_sig)(int,char,double,void*);//RegistrationregisterCallback(void*app_obj,func_sigfunc){_app_obj=app_obj;_func=func;}//Callingwhenthetimecomesvoidcall_app_code(){_func(231,'a',432.4234,app_obj);}//Otherusefulmethodsprivate:void*app_obj;func_sig_func;//Oth

c++ - 绑定(bind) lambda 的速度(通过 std::function)与仿函数结构的 operator()

autolam=[](inta,intb,intc){returna在版本一中,我们std::vector>lamvals;//getparametersandforeachlamvals.emplace_back(std::bind(lam,a,std::placeholders::_1,b));替代方案是std::vectorlamvals;//getparametersandforeachlamvals.emplace_back(functor{a,b});在这两种情况下我们都有一个简单的迭代returnstd::any_of(lamvals.cbegin(),lamvals.c