(no title)
ben-schaaf | 2 days ago
std::unique_ptr<int> a;
printf("%d\n", *a);
Similarly unique_ptr::operator[] doesn't (and can't) do bounds checking, for example: std::unique_ptr<int[]> a = std::make_unique<int[]>(2);
printf("%d\n", a[2]);
There's also no attempt to limit the construction of invalid smart pointers, for example: int num;
std::unique_ptr<int> a(&num);
Smart pointers simplify memory management, and they're slightly harder to misuse than regular pointers, but they simply make no attempt at providing memory safety.
No comments yet.