草庐IT

move_member

全部标签

c++ - 错误 C2039 : 'vector' : is not a member of 'std'

我是C++的新手,我正在尝试制作一款地牢爬虫小游戏。目前我在我的头文件中声明了多个vector,但它们似乎给出了多个错误。我曾尝试在StackOverflow上搜索此问题,但答案似乎并不奏效。这是我的头文件之一:(Hero.h)#pragmaonceclassHero{public:Hero();std::stringname;intexperience;intneededExperience;inthealth;intstrength;intlevel;intspeed;std::vectoritems=std::vector();voidlevelUp();private:};这是

c++ - "error: use of deleted function"在 move 构造函数中对 unique_ptr 调用 std::move 时

#includeclassA{public:A(){}A(constA&&rhs){a=std::move(rhs.a);}private:std::unique_ptra;};此代码无法使用g++4.8.4编译并抛出以下错误:error:useofdeletedfunction‘std::unique_ptr&std::unique_ptr::operator=(conststd::unique_ptr&)[with_Tp=int;_Dp=std::default_delete]’a=std::move(rhs.a);^我知道unique_ptr的复制构造函数和复制赋值构造函数已删除

c++ - 错误 : ‘list’ is not a member of ‘std’ and error: template argument 2 is invalid

我正在尝试编译我的头文件,但我遇到了我无法弄清楚的错误。我想创建一个包含3个映射的结构:-从单个单词映射到计数-从词对映射到计数-从单个单词映射到后续单词列表我的头文件中的代码:#include#include#include#include#include#include#include#includetypedefstruct{std::mapfirstCounts;std::mappairCounts;std::map>follows;//Youcanuseaniteratortoretrievethevaluesstoredinthelist.}LanguageModel;我得

c++ - std::move 和 std::copy 是否相同?

我尝试做类似的事情:std::copy(std::make_move_iterator(s1.begin()),std::make_move_iterator(s1.end()),std::make_move_iterator(s2.begin()));出现这个错误:error:usingxvalue(rvaluereference)aslvalue*__result=std::move(*__first);这让我感到困惑。如果您使用std::move,也会发生同样的事情。看起来GCC内部使用了一个名为std::__copy_move_a的函数,它move而不是复制。使用std::co

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++ - 为什么这里调用复制构造函数,而不是 move 构造函数?

我有一个类,PlayerInputComponent:.h:classPlayerInputComponent{public:PlayerInputComponent(PlayerMoveComponent&parentMoveComponent_,std::unique_ptrinputConverter_);PlayerInputComponent(PlayerInputComponent&&moveFrom);voidupdate();private:std::unique_ptrinputConverter;PlayerMoveComponent&parentMoveCompo

c++ - 子类中的默认 move 构造函数

在C++11中,如果基类定义了自己的move(复制)构造函数(赋值运算符),子类是否需要在调用基类的地方定义自己的move(复制)构造函数(赋值运算符)显式调用相应的构造函数/运算符?每次都清楚地定义构造函数、析构函数、move/复制构造函数(赋值运算符)是个好主意吗?structBase{Base(){}Base(Base&&o);};structSub:publicBase{Sub(Sub&&o);//NeedIdoitexplicitly?Ifnot,whatthecompilerwilldoforme}; 最佳答案 如果您没

c++ - 使用 std::move 返回时 "return-by-rvalue-ref"和 "return-by-value"之间的区别?

考虑以下代码:#includeusingnamespacestd;structI{I(I&&rv){coutC包含I。而C::foo()允许您将I移出C。上面使用的成员函数有什么区别:I&&foo(){returnmove(i)};//returnrvalueref和以下替换成员函数:Ifoo(){returnmove(i)};//returnbyvalue对我来说,它们似乎做同样的事情:Ii=c.foo();导致调用I::I(I&&);.本例未涉及的会有什么后果? 最佳答案 撇开您编写的程序是否真正有意义的考虑因素(从数据成员移动

c++ - 没看懂Stroustup先生建议删除抽象类Shape的copy default和move操作

我试图理解作者在他的新书(TCPL第4版)中3.3.4SuppressingOperations中的建议,但无济于事。书摘Usingthedefaultcopyormoveforaclassinahierarchyistypicallyadisaster:Givenonlyapointertoabase,wesimplydon’tknowwhatmembersthederivedclasshas(§3.3.3),sowecan’tknowhowtocopythem.So,thebestthingtodoisusuallytodeletethedefaultcopyandmoveoper

c++ - 返回成员变量时如何利用 move 语义?

我正在实现一个构建uint8_tvector的工厂类。我希望能够在返回结果vector时利用move语义。这似乎可行,但我不确定这是完成我想要的事情的正确方法。我已经看到很多关于如何将返回的自动变量视为右值并使用调用代码的move构造函数的示例,但在我的示例中,返回的对象是一个成员。我知道如果调用者将返回值放入move构造函数中,成员将丢失其内容-这正是我想要的。我是这样写的:#include#include#includeclassFactory{public:std::vector_data;Factory(std::size_tsize):_data(size,0){}voidb