#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
class A
{
public:
A(){}
A(const A &a) { cout << "拷贝构造" << endl; }
};
int main()
{
vector<A> va(3);
return 0;
}
...全文
52413打赏收藏
创建一个vector,为什么会调用拷贝构造函数?
如下代码,拷贝构造函数为什么会调用3次? #include #include using std::cout; using std::endl; using std::vector; class A { public: A(){} A(const A &a) { cout << "拷贝构造" << endl; } }; int main() { vector va(3); return 0; }