#define _CRTDBG_MAP_ALLOC
#include<crtdbg.h>
#include<iostream>
#include<vector>
#include<memory>
using namespace std;
void f1() {
vector<int*> vec;
vec.push_back(new int(5));
vec.push_back(new int(6));
//cout << *vec[0];
}
void f2(){
vector<shared_ptr<int>> vec;
vec.push_back(shared_ptr<int>(new int(5)));
vec.push_back(shared_ptr<int>(new int(6)));
//cout << *vec[0];
}
int main() {
//f1(); 会泄漏
f2();
_CrtDumpMemoryLeaks();
return 0;
}
vector<shared_ptr>与内存泄漏
最新推荐文章于 2024-02-14 18:54:55 发布