smart pointer in C++11 (notes)


auto c = make_shared<circle>(12);
auto ints = make_unique<int[]>(new int[10]);

// customize deleter
// wrap C pointer
auto stmt = make_shared<sqlite3_stmt>(nullptr, [](sqlite3_stmt * stmt){
	sqlite3_free(stmt);
	stmt = nullptr;
});

const char * sql_template = "delete from BOOK where book_id = '%s';";
size_t sql_length = std::strlen(sql_template) + sizeof(T);
std::unique_ptr<char[]> sql(new char[sql_length]);
std::snprintf(sql.get(), sql_length, sql_template, book_id.c_str());

本文地址:http://zisxks.com/2014/04/06/smart-pointer-in-Cpp11
分享到 Share: 0

欢迎转载,转载请注明作者及出处zisxks.com,请勿用于商业用途