136
General discussions / Re: Why RAII rocks
« on: October 10, 2012, 09:33:12 pm »Quote
While it isn't significant, any smart pointer creates a tracking object; that is, an object (wrapper) to hold the raw pointer itself.
#include <iostream>
#include <memory>
int main()
{
std::unique_ptr<int[]> pointer(new int[32]) ;
std::cout << "Size of pointer: " << sizeof(pointer)
<< "\nSize of int*: " << sizeof (int*) << '\n' ;
}
#include <memory>
int main()
{
std::unique_ptr<int[]> pointer(new int[32]) ;
std::cout << "Size of pointer: " << sizeof(pointer)
<< "\nSize of int*: " << sizeof (int*) << '\n' ;
}
Output:
Size of pointer: 4
Size of int*: 4
Gee. Where did they hide that tracking object?