草庐IT

copy-constructor

全部标签

c++ - 假设没有编译器优化,这个对象会被创建多少次?

假设没有编译器优化。将创建多少次OutputBuffer_s类型对象?#include#includestructOutputBuffer_s{intencoded[10];};OutputBuffer_sfunc(){OutputBuffer_ss;returns;}intmain(){OutputBuffer_sa=func();}最初,我假设了3次。1)当调用func()时,将在堆栈上创建对象s。2)当func()超出范围时,它会将对象s的拷贝返回给main()。3)将值复制到main()中的对象a,因为func()返回的值是临时值。我知道我在这里错了,因为我在g++中使用-O0

WebMvcSecurityConfiguration$CompositeFilterChainProxy]: Constructor threw exception

在参考spring-authorization-server的入门时根据DefiningRequiredComponents配置完SecurityConfig.java,启动时没有问题,但把注解@EnableWebSecurity设置为@EnableWebSecurity(debug=true)时:@Configuration@EnableWebSecurity(debug=true)publicclassSecurityConfig{......}应用启动报错:org.springframework.beans.factory.BeanCreationException:Errorcreat

c++ - 如果在 C++ 类中省略复制构造函数,会发生什么(确切地)?

如果您在C++类中省略复制构造函数(确切地)会发生什么?该类是否只是memcpy或复制的成员明智? 最佳答案 类是按成员复制的。这意味着调用了所有成员的复制构造函数。 关于c++-如果在C++类中省略复制构造函数,会发生什么(确切地)?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/5134155/

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++ Array of 120 ob​​jects with constructor + parameters, header- + sourcefile, no pointers please!

文件.h:externobjektsquares[120];文件.cpp:objektsquares[120]={objekt(objekt_size,objekt_size,-111,0)};我怎样才能一次初始化所有对象,所有对象都使用相同的参数? 最佳答案 不要使用原始数组(因为所有元素都将通过默认构造函数初始化)。使用例如一个std::vector:std::vectorsquares(120,objekt(objekt_size,objekt_size,-111,0)); 关于C

c++ - 复制构造函数、析构函数和赋值运算符。我们什么时候不需要它们?

我知道在你的类中添加cctor、dtor或op=时的C++经验法则,你还需要添加另外两个以使你的类在所有情况下都能正常工作。是否存在不需要提供全部三个而只需提供其中一两个的情况?如果您将其中一个添加到您的类中,为什么C++不要求您将它们全部添加?编辑1:当您不仅不需要其中一些,而且不想拥有它们时,您提到了示例,因此您希望将它们设为私有(private)或protected。但是即使是空体,您仍然需要在代码中编写它们。当你通过添加一个空主体的虚拟析构函数来使类多态时,我没有全部拥有它们的唯一正当理由。但是一旦你在析构函数的主体中写了一些东西,你就应该考虑在cctor和op=的主体中也写一

c++ - 使用 g++ 编译 C++ 时出现 'hides constructor for' 警告是什么意思?

使用以下代码:#includestructmy_struct{inta;intb;my_struct();};my_struct::my_struct(void){printf("constructor\n");}voidmy_struct(void){printf("standardfunction\n");}intmain(intargc,char*argv[]){structmy_structs;s.a=1;s.b=2;printf("%d-%d\n",s.a,s.b);return0;}我在使用g++-Wshadowmain.cpp编译时收到警告:main.cpp:15:20:

c++ - 使用 C++0x : call to deleted constructor of 时的 clang++ 错误消息

您好,我已经将我的Xcode升级到4.2版,并将clang++升级到以下版本:Appleclangversion3.0(tags/Apple/clang-211.10.1)(basedonLLVM3.0svn)Target:x86_64-apple-darwin11.2.0Threadmodel:posix当尝试使用clang-std=c++0x编译以下代码时#include#include#includeclassilpConstraintImpl{public:virtual~ilpConstraintImpl(){}};classilpConstraint{public:ilpC

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)