I've been playing around with smart pointers in C++. I'm curious as to why Valgrind shows memory leaks with this unique_ptr implementation.
#include <iostream>
#include <memory>
#include <vector>
int main()
{
std::unique_ptr<std::vector<int>> ptr{new std::vector<int>};
std::cout << ptr.get() << std::endl;
ptr->emplace_back(1);
ptr->emplace_back(2);
ptr->emplace_back(3);
for (size_t i = 0; i < ptr->size(); i++)
{
std::cout << " " << (*ptr)[i];
}
std::cout << std::endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire