草庐IT

compound-assignment

全部标签

c++ - QML:在 QML 中使用 cpp 信号总是导致 "Cannot assign to non-existent property"

我只是想将一个cpp信号连接到一个qml槽并尝试了不同的方法,但它总是在运行时导致相同的QML错误:无法分配给不存在的属性“onProcessed”!为什么?这是我的Cpp对象:#includeclassImageProcessor:publicQObject{Q_OBJECTpublic:explicitImageProcessor(QObject*parent=0);signals:voidProcessed(constQStringstr);publicslots:voidprocessImage(constQString&image);};ImageProcessor::Ima

C++ move 语义 : why copy assignment operator=(&) is called instead of move assignment operator=(&&)?

我有以下代码:#include#includeusingstd::cout;structSomeType{SomeType(){}SomeType(constSomeType&&other){cout我希望move构造函数调用move赋值运算符。下面是这个程序的输出:SomeType(SomeType&&)operator=(constSomeType&)operator=(SomeType&&)如您所见,move赋值运算符已成功调用,但在move构造函数内分配给*this时未成功调用。为什么会发生这种情况,我能以某种方式解决它吗? 最佳答案

c++ - 错误 :incompatible types in assignment of 'const char[5]' to 'char[10]'

我已经将c定义为charc[][10]在函数定义中并像c[i]="gray";一样使用它怎么了?我在网上搜索,它显示相同的语法。谢谢。 最佳答案 您不能对数组使用赋值(=)。如果将c更改为指针数组,这可能会起作用,具体取决于您需要使用它做什么。constchar*c[20];c[i]="gray";或者如果声明的类型必须是数组的数组,您可以使用strncpy:charc[20][10];strncpy(c[i],"gray",sizeof(c[i])); 关于c++-错误:incompa

c++ - 使用 boost::assign::list_of 构造 std::vector 时的歧义

这段代码:std::vector(boost::assign::list_of(1)(2)(3));给出错误:main.cpp:Inmemberfunction'void::RequestHandler::processRequest(Foo&,Bar,unsignedint,unsignedint*,constchar*,boost::shared_ptr&)':main.cpp:450:error:callofoverloaded'vector(boost::assign_detail::generic_list&)'isambiguous/4.4.2/bits/stl_vecto

c++ - std::vector::assign/std::vector::operator=(const&) 是否保证重用 `this` 中的缓冲区?

如果我将一个vector分配或复制到另一个vector(其容量与前者的大小相同或更大),我可以假设后者的缓冲区将被重用吗?下面的例子证明我可以,但是,标准保证吗?std::vector::assign和std::vector::operator=在这方面的行为有什么不同吗?#include#include#includeintmain(){std::vectora{1,2,3,4,5};std::vectorb{1,2,3,4};std::vectorc{1,2,3,4,5,6,7,8,9,10};std::coutLiveexample.更新:Thisanswer提到voidassi

c++ - is_assignable 和 std::unique_ptr

Here是来自gcc的测试文件,livedemostructdo_nothing{templatevoidoperator()(T*){}};intmain(){inti=0;std::unique_ptrp1(&i);std::unique_ptrp2;static_assert(!std::is_assignable::value,"");//note!here.}std::is_assignableIftheexpressionstd::declval()=std::declval()iswell-formedinunevaluatedcontext,providesthemem

c++ - 为什么 boost::assign::list_of 不适用于 pair<string, vector<string>>?

我不明白为什么这不起作用(VisualC++2012):#include#include#include#includeusingnamespacestd;intmain(){pair>("^",boost::assign::list_of("rules"));}错误是:include\utility(138):errorC2668:'std::vector::vector':ambiguouscalltooverloadedfunctionwith[_Ty=std::string]include\vector(786):couldbe'std::vector::vector(std:

c++ - STL - 赋值运算符与 `assign` 成员函数

vector(以及list和其他容器)有一个成员函数(MF)assign。我想比较assignMF(范围版本)与赋值运算符。据我所知,在以下情况下使用assign很有用:想要分配vector的子范围(不是从头到尾)。赋值是从一个数组完成的。在其他情况下,assignMF没有缺点,可以使用赋值运算符。我对吗?使用assignMF是否还有其他一些原因? 最佳答案 使用assign的主要原因就是将数据从一种容器复制到另一种容器。例如,如果您要迁移std::set的内容到std::vector,你不能使用赋值运算符,但你可以使用vector

c++ - 使用哪个 : move assignment operator vs copy assignment operator

我似乎不明白为什么要使用移动赋值运算符:CLASSA&operator=(CLASSA&&other);//moveassignmentoperator结束了,复制赋值运算符:CLASSA&operator=(CLASSAother);//copyassignmentoperator移动赋值运算符仅采用r值引用,例如CLASSAa1,a2,a3;a1=a2+a3;在复制赋值运算符中,other可以是使用复制构造函数或移动构造函数的构造函数(如果other是用右值初始化的,它可以是移动构造的——如果move-constructor定义了——)。如果它是copy-constructed,我

Object.assign详解

目录一、Object.assign是什么?二、用法:三、详细讲解1.目标对象和源对象没有同名属性2.目标对象和源对象有同名属性3.有多个源对象4、原始类型会被包装为对象5、对象的拷贝6、对象的深拷贝7、对象的深拷贝总结一、Object.assign是什么?object.assign()主要用于对象合并,将源对象中的属性复制到目标对象中,他将返回目标对象。二、用法:Object.assign(target,...sources)参数:target--->目标对象      source--->源对象返回值:target,目标对象三、详细讲解1.目标对象和源对象没有同名属性vartarget={n