fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. class myCla {
  5. public:
  6. ~myCla() { std::cout << "hello RAII" << std::endl; };
  7. };
  8.  
  9. std::unique_ptr<myCla[]> ownerPointerCreator(size_t nElem) {
  10. return std::unique_ptr<myCla[]>(new myCla[nElem]);
  11. };
  12.  
  13. int main() {
  14. /*std::unique_ptr<myCla[]>*/ auto uniquee = ownerPointerCreator(10);
  15. //creates unique_ptr to 10 elements which are automatically deleted
  16. std::cout << "ohoho" << std::endl;
  17. return 0;
  18. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
ohoho
hello RAII
hello RAII
hello RAII
hello RAII
hello RAII
hello RAII
hello RAII
hello RAII
hello RAII
hello RAII