Unique pointers?

Hi,
I am new to smart pointers so I want someone to clarify that the memory will be deleted after the program loses scope.

1
2
3
4
    const char* query = {"SELECT * FROM `USERS` WHERE `USER_ID` = 1;"};
    auto rs = unique_ptr<Leaf::Records>(db->getRecords(query));
    Leaf::Record* r = rs->getRecord(0);


In the database libary I wrote it uses the standard pointers. Now that I have made a unique pointer pointing to the record it should delete the memory once the scope is left right?
The delete operator will be called on the return value of db->getRecords(query) when rs goes out of scope.
yes, as soon as unique_ptr goes out of scope it's destroyed and it's memory is deallocated.
codekiddy wrote:
yes, as soon as unique_ptr goes out of scope it's destroyed and it's memory is deallocated.
unique_ptr is a template, not a variable - once brought into scope it cannot go out of scope.
Topic archived. No new replies allowed.