c++ - 这个 c++ 向量初始化会导致内存泄漏吗?
问题描述
我有以下代码:
#include <iostream>
#include <vector>
class Test
{
public:
int first;
int second;
Test(int a, int b)
{
first = a;
second = b;
}
};
int main(int argc, char* argv[])
{
std::vector<Test> mydata({ Test(4, 8), Test(5, 3), Test(12, 7), Test(8, 9) });
for (auto const&y : mydata)
{
std::cout << y.first << " / " << y.second << std::endl;
}
//need to free vector here or sth?
return 0;
}
我使用类构造函数来初始化向量。上面的代码是好的还是会导致错误?我应该在程序结束时释放向量吗?
解决方案
推荐阅读
- github - 如何在 github 上重新启动已取消的检查?
- visual-studio - 如何让我的 git 历史更加连贯?
- tensorflow - keras load_model 无法识别新的 AUC 指标 tf.keras.metrics.AUC()
- c# - 让相机在没有相机胶卷的情况下统一跟随球
- javascript - vb.net 这是反射吗
- fortran - Fortran if 显示全部且未选中
- linux - 核心转储未生成
- javascript - 发送到 PHP 时如何处理已发布的 multipart/form-data?
- c++ - 缓冲区参数为 NULL
- php - 如何调整openssl证书位置