example
解释
- vector在resize的时候,就会初始化变量
- vector[0] = input, 这里会调用编译器为类添加的默认赋值拷贝函数
code
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <vector>
class Mat
{
public:
Mat(): w(0)
{
printf("mat init... \n");
}
Mat(int size): w(size)
{
}
int w;
};
int main(int argc, char **argv){
std::vector<Mat> blob_mat;
printf("000000 \n");
blob_mat.resize(5);
printf("111111 \n");
Mat input(3);
printf("input.w = %d \n", input.w);
blob_mat[1] = input; // 编译器 默认添加的 复制构造函数
Mat blob;
for(int i=0; i<5; i++)
{
blob = blob_mat[i];
printf("blob.w: %d \n", blob.w);
}
return 0;
}