fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. namespace rocksdb {
  5. class DB {
  6. public:
  7. virtual ~DB() = default;
  8. virtual void doIt() = 0;
  9. static void Open(DB **db);
  10. };
  11.  
  12. class DB_Impl : public DB {
  13. public:
  14. DB_Impl() { std::cout << "Created" << std::endl; }
  15. ~DB_Impl() { std::cout << "Destroyed" << std::endl; }
  16. void doIt() override {}
  17. };
  18.  
  19. void DB::Open(DB **db) {
  20. *db = new DB_Impl;
  21. }
  22. }
  23.  
  24. int main() {
  25.  
  26. std::unique_ptr<rocksdb::DB> _db;
  27.  
  28. rocksdb::DB* db;
  29. rocksdb::DB::Open(&db);
  30. _db = std::unique_ptr<rocksdb::DB>(db);
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5520KB
stdin
Standard input is empty
stdout
Created
Destroyed