#include#include class MyClass { public: MyClass() { std::cout << "MyClass constructor called." << std::endl; } ~MyClass() { std::cout << "MyClass destructor called." << std::endl; } }; int main() { OwnPtrWillBeRawPtr ptr(new MyClass()); return 0; }
#includeIn this example, the OwnPtrWillBeRawPtr instance is passed by reference to a function called myFunction. This function can modify the pointer as needed, but ownership of the allocated memory remains with the caller. When the program terminates, the destructor of the main function will free the memory allocated for the MyClass instance. Package library: Chromium#include class MyClass { public: MyClass() { std::cout << "MyClass constructor called." << std::endl; } ~MyClass() { std::cout << "MyClass destructor called." << std::endl; } }; void myFunction(OwnPtrWillBeRawPtr & ptr) { // ... } int main() { OwnPtrWillBeRawPtr ptr(new MyClass()); myFunction(ptr); return 0; }