草庐IT

move_pages

全部标签

c++ - Qt C++ : Moving a file, 源路径和目标路径在不同的驱动器上

我想在C++中将一个文件从一个文件夹(比如在驱动器C上)移动到另一个文件夹(比如在驱动器D上)。如果该文件已经存在于目标文件夹中,它应该覆盖它。如何使用C++std库或Qt实现它?我找到了“重命名”方法,但我不确定如果路径位于不同的驱动器上,它是否会起作用。另外,什么是平台依赖? 最佳答案 只需使用QFile::rename().对于大多数目的,它应该做大致正确的事情。我认为C++标准库没有文件系统间重命名调用(如果我错了,请在评论中纠正我!),std::rename只能在单个文件系统内移动。然而,通常这里唯一(相关的)原子文件操作

c++ - 通过 destruct+move 构造的 move 分配安全吗?

这里有一个非常简单的方法来为大多数带有move构造函数的类定义move赋值:classFoo{public:Foo(Foo&&foo);//youstillhavetowritethisoneFoo&operator=(Foo&&foo){if(this!=&foo){//avoiddestructingtheonlycopythis->~Foo();//callyourowndestructornew(this)Foo(std::move(foo));//callmoveconstructorviaplacementnew}return*this;}//...};在标准C++11中,

c++ - move 构造函数不能默认

我是c++11的新手并编写了以下类,我希望它支持std::move:classX{public:X(intx):x_(x){}~X(){printf("X(%d)hasbereleased.\n",x_);}X(X&&)=default;X&operator=(X&&)=default;X(constX&)=delete;X&operator=(constX&)=delete;private:intx_;};但是,当我使用选项-std=c++0x编译它时,编译器会报错如下:queue_test.cc:12:error:‘X::X(X&&)’cannotbedefaultedqueue_

c++ - move 分配给自己的行为

这个问题在这里已经有了答案:Whatdoesthestandardlibraryguaranteeaboutselfmoveassignment?(2个答案)关闭8年前。示例代码:#includeintmain(){std::vectorw(20,123),x;w=std::move(w);std::coutg++4.8.3上的输出:0当然,标准规定move赋值运算符使操作数处于未指定状态。例如,如果代码是x=std::move(w);那么我们期望w.size()为零。但是,是否有特定的顺序或其他条款涵盖自行搬家的情况?size是否为0未说明或20,或其他东西,或未定义的行为?标准容器

c++ - 默认 move 构造函数和引用成员

来自N3337的[12.8][11]:Theimplicitly-definedcopy/moveconstructorforanon-unionclassXperformsamemberwisecopy/moveofitsbasesandmembers.[Note:brace-or-equal-initializersofnon-staticdatamembersareignored.Seealsotheexamplein12.6.2.—endnote]Theorderofinitializationisthesameastheorderofinitializationofbases

c++ - QML : Navigation between qml pages from design perception

我们需要开发一个QtQuick项目,其中我们有大约100个屏幕。我曾尝试为导航制作一个演示项目,点击按钮后会出现三个屏幕。我在页面之间的导航中使用了“状态”的概念。最初我尝试使用“加载器”进行相同的操作,但加载器无法保留页面的先前状态,它在导航期间重新加载整个页面。下面是main.qml的代码片段//importQtQuick1.0//totargetS605thEditionorMaemo5importQtQuick1.1Rectangle{id:main_rectanglewidth:360height:640Page1{id:page1}Page2{id:page2}Page3{

c++ - 使用不可复制(但可 move )键 move 分配 map 时出错

为什么这不起作用:#include#includestd::map,std::unique_ptr>foo();std::map,std::unique_ptr>barmap;intmain(){barmap=foo();return0;}虽然这样做:#include#includestd::map,std::unique_ptr>foo();std::map,std::unique_ptr>barmap;intmain(){std::map,std::unique_ptr>tmp(foo());usingstd::swap;swap(barmap,tmp);return0;}这与映射

c++ - std::move() 是否会使迭代器无效?

这个问题在这里已经有了答案:Doesmovingavectorinvalidateiterators?(4个答案)关闭5年前。考虑以下程序:structlist_wrapper{std::vectorm_list;};intmain(){std::vectormyList{1,1,2,3,5};conststd::vector::iteratoriter=myList.begin();list_wrapperwrappedList;wrappedList.m_list=std::move(myList);//CanIstilldereferenceiter?return0;}调用std

c++ - 如何将不可复制和不可 move 的对象分配到 std::map 中?

我有一个对象,我想将其限制为仅在std::map内部分配。这是简化的代码:#includeclassValue{public:Value(intvalue){_value=value;}Value(constValue&)=delete;Value&operator=(constValue&)=delete;Value(Value&&)=default;//***void*operatornew(size_t)=delete;//notonfreestoreprivate:int_value;};classContainer{public:Container();Value*addTo

c++ - 为什么我必须在右值引用上调用 move?

在下面的代码中,为什么第一个调用mkme=mvme_rv不分派(dispatch)给T&operator=(constT&&)?#include#include#includeusingnamespacestd;usingT=vector;intmain(){Tmvme(10,1),mkme;T&&mvme_rv=move(mvme);//rvalueref?mkme=mvme_rv;//callsT&operator=(constT&)?cout 最佳答案 正如skypjack正确评论的那样,通过名称访问对象总是会产生左值引用。这