草庐IT

working-copy

全部标签

c++ - 对于具有抛出复制构造函数和 noexcept 按值复制赋值的类,is_nothrow_copy_assignable 的值是多少?

根据C++标准,以下程序的预期(如果有)输出是什么:#include#include#includeclassA{public:A()=default;~A()=default;A(Aconst&other){}A(A&&other)noexcept{}A&operator=(Aother)noexcept{return*this;}};intmain(){std::cout::value::value换句话说,类型特征值的评估是否只看赋值运算符的声明,即noexcept,并因此产生truetrue或者它是否考虑调用上下文(a、b是A的实例)a=b;//maythrow,implici

c++ - 错误 : copy assignment operator not allowed in union

当出现以下错误时,我正在编译下面的代码。我找不到原因。typedefunion{struct{constintj;}tag;}X;intmain(){return0;}error:member`::``::tagwithcopyassignmentoperatornotallowedinunion虽然这段代码使用gcc编译罚款。仅使用g++时出错。 最佳答案 为了拥有某个类类型T的union成员,T的特殊成员函数(默认构造函数、复制构造函数、复制赋值运算符、和析构函数)必须是微不足道的。也就是说,它们必须是由编译器隐式声明和定义的。

c++ - 为什么memcpy复制Eigen矩阵数据失败,std::copy成功?

当我使用Eigen创建矩阵时,如下所示:Eigen::MatrixXdM(3,3);M产生147258369我可以用指针遍历数据,打印每个元素:double*d=M.data();for(inti=0;i产生123456789我还可以使用std::copy将其复制到堆栈上相同类型的数组,然后打印该数组的元素:doubledata_copy[9];std::copy(M.data(),M.data()+M.size(),data_copy);for(inti=0;i产生123456789但是,我似乎无法使用memcpy进行等效复制。这只能复制第一个元素:doubledata_memcop

c++ - 在 VC2015 中连接不匹配的字符串 WORKS - 如何?

当我们有这些之一时:autocity1="New"L"Delhi";autocity2=L"New""York";任何VS2015之前的编译器都会引发错误:errorC2308:concatenatingmismatchedstrings但是使用VC2015编译器,它编译得很好并且结果类型(auto推导)是一个宽字符字符串。我的问题是:何时以及如何做到这一点-任何标准规范? 最佳答案 在C++03中,此行为是未定义的。ISO14882-2003:2.13.4.3指出Intranslationphase6(2.1),adjacentn

c++ - QSettings(Qt 5.4) : setValue doesn't work properly

在我的.cpp中,我正在使用QSettings。这以前在Qt4.8中有效:#include----------QSettingssettings;settings.setValue("time_axis_direction",1);inttest_var=settings.value("time_axis_direction").toInt();----------test_var程序返回0,请问是什么原因?我将Qt与VS插件一起使用。 最佳答案 根据docs,你必须设置组织名称和应用程序名称:QCoreApplication::s

C++11 原子 : why does this code work?

让我们采用这个结构:structentry{atomicvalid;atomic_flagwriting;charpayload[128];}两个线程A和B以这种方式同时访问这个结构(让e成为entry的一个实例):if(e.valid){//dosomethingwithe.payload...}else{while(e.writing.test_and_set(std::memory_order_acquire));if(!e.valid){//writee.payloadonebyteatatime//(thepayloadwrittenbyAmaybedifferentfrom

c++ - 在基类和派生类中 copy-and-swap

我最近读到copy&swap现在我正在尝试在基类和派生类中实现ctors。我的基类和派生类中都有四个构造函数,但是我不确定如何实现派生类的赋值运算符。explicitBase(inti):m_i{i}{}Base(constBase&other):m_i{other.m_i}Base(Base&&other):Base(0){swap(*this,other);}Base&operator=(Baseother){swap(*this,other);return*this;}friendvoidswap(Base&a,Base&b)noexcept{usingstd::swap;swa

c++ - 通过 copy 和 decltype 捕获 Lambda 引用

考虑简单的程序:inti=0;int&j=i;autolambda=[=]{std::cout根据[expr.prim.lambda],闭包成员变量j的类型应该是int:Anentityiscapturedbycopyifitisimplicitlycapturedandthecapture-defaultis=orifitisexplicitlycapturedwithacapturethatisnotoftheform&identifieror&identifierinitializer.Foreachentitycapturedbycopy,anunnamednon-static

c++ - std::reverse_copy "error: function call has aggregate value"

#include#include#include#includeusingnamespacestd;intmain(){intarrA[]={1,2,3,4,5,6,7,8,9};vectorvecIntA(arrA,arrA+sizeof(arrA)/sizeof(arrA[0]));vectorvecIntB(vecIntA.size());//copy((vecIntA.rbegin()+3).base(),(vecIntA.rbegin()+1).base(),vecIntB.begin());//OKvector::iterators=(vecIntA.rbegin()+3)

c++ - 错误 : definition of implicitly declared copy constructor

我目前正在处理的QtC++项目有问题。这是我要介绍的一个新部分,但我发现它有点令人困惑。我创建了一些由股票、债券和储蓄类继承的Assets类。这一切都很好。然后我创建了一个名为AssetList的类,它派生了QList,这个类是我发现问题的地方。这是我目前的代码。资源列表.h#ifndefASSET_LIST_H#defineASSET_LIST_H#include"Asset.h"#includeclassAssetList:publicQList{public:AssetList(){}~AssetList();booladdAsset(Asset*);Asset*findAsse