vector压入对象使用注意事项:
- 无参构造器自实现
- reserve() 预留空间
- 如申请堆内存,自实现拷贝构造和移动构造
- 压入栈中的对象,不需要析构
API 使用:
class A
{
public:
A() {
cout<<"A():"<<this<<endl;
}
A(int i):_data(i)
{
cout<<"A(i):"<<this<<endl;
}
A(const A & other) {
cout<<"const A & other :"<<this<<"from"

文章讲述了在C++中使用vector时,特别是在压入元素、resize操作和insert方法时,涉及的构造函数(包括无参构造、拷贝构造和移动构造)的重要性,以及自实现无参构造器以避免编译错误的必要性。
最低0.47元/天 解锁文章
4962

被折叠的 条评论
为什么被折叠?



