草庐IT

unshared_copy

全部标签

c++ - Visual Studio C++ - 缺少 "Copy to Output Directory"

这个问题在这里已经有了答案:Automaticcopyfilestooutputduringapplicationbuilding(8个答案)关闭9年前。我在VisualStudio(2012)中创建了一个空的C++项目,当我在解决方案资源管理器中选择了某个文件时,在“属性”窗口中看不到“复制到输出目录”选项。为什么?

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,我

c++ - ‘operator=’ 的模糊重载与 c++11 std::move and copy and swap idiom

我收到以下错误:[matt~]g++-std=c++11main.cpp-DCOPY_AND_SWAP&&./a.outmain.cpp:Infunction‘intmain(int,constchar*const*)’:main.cpp:101:24:error:ambiguousoverloadfor‘operator=’in‘move=std::move((*©))’main.cpp:101:24:note:candidatesare:main.cpp:39:7:note:Test&Test::operator=(Test)main.cpp:52:7:note:Test&

c++ - 为什么 std::copy_n 采用模板参数而不是 std::size_t?

这么简单的问题。templateOutputItcopy_n(InputItfirst,Sizecount,OutputItresult);为什么std::copy_n为要复制的元素数量取一个类型,而不是简单地std::size_t?我只是想不出一个理由。templateOutputItcopy_n(InputItfirst,std::size_tcount,OutputItresult); 最佳答案 在这种情况下,推测原始原理大多是徒劳的,但对于这种设计copy_n可以用负计数调用,例如int或ptrdiff_ttype,在这种情

c++ - 如何实现类似 std::copy_if 但在插入到不同容器之前应用函数的方法

完全公开,这可能是一个锤子和钉子的情况,在不需要的时候尝试使用STL算法。我在我正在使用的一些C++14代码中看到了一个重新出现的模式。我们有一个迭代的容器,如果当前元素符合某些条件,那么我们将其中一个元素字段复制到另一个容器。模式是这样的:for(autoit=std::begin(foo);it!=std::end(foo);++it){autox=it->Some_member;//Note,thecheckusuallyusesthefieldwouldaddtothenewcontainer.if(f(x)&&g(x)){bar.emplace_back(x);}}这个想法几

c++ - 如何在 boost::filesystem 中使用 copy_file?

我想将一个文件从一个目录复制到另一个目录,但我的程序总是因为某些原因而中止。之前有没有人这样做过,可以告诉我哪里出了问题吗?我怎么能捕捉到copy_file抛出的异常,我查看了boost网站,但我找不到任何关于异常的相关信息。pathuser_path("C:\\MyFolder");boost::filesystem::create_directory(user_path);pathfile("C:\\Another\\file.txt");boost::filesystem::copy_file(file,user_path);谢谢, 最佳答案

c++ - Stroustrup 的 Can_Copy 模板如何工作?

Stroustrup提供了一个Can_copytemplate.它是如何工作的?templatestructCan_copy{staticvoidconstraints(T1a,T2b){T2c=a;b=a;}Can_copy(){void(*p)(T1,T2)=constraints;}};特别是,为什么他需要行void(*p)(T1,T2)=constraints;而不是空构造函数?是否允许编译器仅生成特定模板实例用作优化的函数? 最佳答案 这是因为生成的代码中不存在模板中未使用的成员函数,因此要检查约束,您必须在某处显式调用c

c++ - 为什么 SGI STL 不使用 copy-and-swap 习惯用法?

我最近在StackOverflow上阅读了一个关于Whatisthecopy-and-swapidiom?的答案并且知道copy-and-swap习语可以avoidingcodeduplication,andprovidingastrongexceptionguarantee.然而,当我查看SGISTLdequeimplementation,我发现它没有使用成语。我想知道为什么不,如果这个习语在某种程度上像“最佳实践”?deque&operator=(constdeque&__x){constsize_type__len=size();if(&__x!=this){if(__len>=

c++ - 为什么assign前要有copy?

我正在做以下测试:#include#includeusingnamespacestd;classA{private:inti;public:A():i(1){cout输出是:AconstrAconstrAcopyAassigndestructAdestructAdestructA好像“o2=o1”是先复制后赋值,不知道这背后的故事是什么。谢谢! 最佳答案 因为您按值传递给赋值运算符:voidoperator=(constAa)您可能打算通过引用传递并且您还应该返回对分配给对象的引用:A&operator=(constA&a){std

c++ - vector push_back 调用 copy_constructor 不止一次?

我对vectorpush_back的行为方式有点困惑,在下面的代码片段中,我希望复制构造函数只被调用两次,但输出表明并非如此。是否是导致此行为的vector内部重组。输出:InsidedefaultInsidecopywithmy_int=0Insidecopywithmy_int=0Insidecopywithmy_int=1classMyint{private:intmy_int;public:Myint():my_int(0){coutmyints;Myintx;myints.push_back(x);x.set(1);myints.push_back(x);