草庐IT

copy_constructor

全部标签

c++ - xutility(2227) : warning C4996: 'std::_Copy_impl'

我收到此警告消息..但我不知道问题出在哪里/哪里..!包括#pragmawarning(push)#pragmawarning(disable:4996)#include#include#include#include#pragmawarning(pop)和警告1>c:\programfiles(x86)\microsoftvisualstudio10.0\vc\include\xutility(2227):warningC4996:'std::_Copy_impl':Functioncallwithparametersthatmaybeunsafe-thiscallreliesont

C++ FileIO Copy -VS- System("cp file1.x file2.x)

编写文件复制例程会更快/更高效,还是我应该只执行对cp的系统调用?(文件系统可能不同[nfs、local、reiser等],但它总是在CentOSlinux系统上) 最佳答案 Invoking一个shell通过使用system()函数效率不高,也不是很安全。在Linux中复制文件最有效的方法是使用sendfile()系统调用。在Windows上,CopyFile()应使用API函数或其相关变体之一。Example使用sendfile:#include#include#include#include#include#include#i

c++ - 类 : handling copy constructor and destructor (C++) 内的 vector

以“big3”(构造函数、复制构造函数、析构函数)的简单类:#includeusingnamespacestd;//actuallygoesintheCfilethatlinkstothisheaderfile...classplanets(){//storesmassandradiidataforplanetsinasolarsystem.public:vectormass;vectorradius;//constructorplanets(intnumObj){for(inti=0;imass(p.mass);//copyvectorsintonewclass.vectorradi

C++ 静态工厂方法与构造函数 : how to avoid copying?

Thisquestion要求以简洁的方式在C++中实现静态工厂方法,thisanswer描述了一种明确的方法。返回值优化将使我们免于制作不必要的Object拷贝,从而使这种创建Object的方式与直接调用构造函数一样高效。在私有(private)构造函数中将i复制到id的开销可以忽略不计,因为它是一个小的int。但是,当Object包含作为类Foo实例的实例变量(需要复杂的初始化逻辑)时,问题和答案并未涵盖更复杂的情况)而不是一个小的原始类型。假设我想使用传递给Object的参数构造Foo。使用构造函数的解决方案如下所示:classObject{Foofoo;public:Object

c++ - 为什么 vector::push_back 和 emplace_back 调用 value_type::constructor 两次?

我有这门课:classFoo{public:Foo(){}Foo(constFoo&){cout然后我插入一个vector:Foofoo{};vf.push_back(foo);输出令人惊讶:constructedbylvaluereference.constructedbylvaluereference.我假设它在传递参数时被复制了,所以我尝试了:vf.push_back(move(foo));和vf.push_back(forward(foo));由于移动语义,输出略有不同,但仍然调用了两次构造函数:constructedbyrvaluereference.constructedb

c++ - C++ 中 std::is_trivially_copy_constructible 中的琐碎操作是什么

这是std::is_copy_constructible(1)和std::is_trivially_copy_constructible文档的摘录(2)关于cppreference.com:1)CheckswhetheratypeisCopyConstructible,i.e.hasanaccessibleexplicitorimplicitcopyconstructor.Iftherequirementismet,amemberconstantvalueequaltrueisprovided,otherwisevalueisfalse.2)Sameas(1),butthecopyco

c++ - 错误 C2512 : no appropriate default constructor available

我收到这个烦人的错误,我不知道为什么=(!这是问题,我解决了,但构造函数有问题。WriteaprogramthatdefinesaclasscalledCirclethatincludesradius(typedouble)asdatamembers.Provideasetandagetfunctionforthisdatamember.Ensurethatthevalueenteredbytheuserisvalidandcorrect(greaterthanzero).Includefunctionmembers:a.functionmemberthatcomputeandretu

c++ - GNU STL 字符串 : is copy-on-write involved here?

(免责声明:我不知道C++标准对此会说什么……我知道,我很糟糕)在处理非常大的字符串时,我注意到std::string正在使用写时复制。我设法编写了最小的循环来重现观察到的行为,例如,下面的循环运行得非常快:#includeusingstd::string;intmain(void){stringbasestr(1024*1024*10,'A');for(inti=0;i在循环体a_copy[1]='B';中添加写入时,显然发生了实际复制,并且程序在0.3秒内运行,而不是几毫秒。100次写入使其速度减慢了大约100倍。但后来变得很奇怪。我的一些字符串没有写入,只是读取,这没有反射(re

c++ - 复制构造函数 : deep copying an abstract class

假设我有以下情况(简化情况):classColor;classIColor{public:virtualColorgetValue(constfloatu,constfloatv)const=0;};classColor:publicIColor{public:floatr,g,b;Color(floatar,floatag,floatab):r(ar),g(ag),b(ab){}ColorgetValue(constfloatu,constfloatv)const{returnColor(r,g,b)}}classMaterial{private:IColor*_color;publ

c++ - ARM C++ ABI : Constructor/destructor return values

我一直在阅读Clang源代码,并发现了一些关于ARMC++ABI的有趣之处,我似乎无法理解其理由。来自ARMABIdocumentation的在线版本:ThisABIrequiresC1andC2constructorstoreturnthis(insteadofbeingvoidfunctions)sothataC3constructorcantailcalltheC1constructorandtheC1constructorcantailcallC2.(对于非虚拟析构函数也是如此)我不确定C1、C2和C3在这里引用什么...本节旨在修改来自通用(即安腾)ABI的第3.1.5节,但