Sobes.tech
Junior — Middle

Kas teil on kogemusi nutikate näidikutega oma projektides?

sobes.tech AI

Vastus AI-lt

Yes, in my projects I have used smart pointers such as std::unique_ptr and std::shared_ptr. They help manage the lifetime of objects and prevent memory leaks. For example, std::unique_ptr provides exclusive ownership of an object and automatically releases memory when it goes out of scope:

#include <memory>

void example() {
    std::unique_ptr<int> ptr = std::make_unique<int>(42);
    // ptr will automatically delete the object when it exits the function
}

std::shared_ptr is used when multiple parts of a program need to share ownership of an object, and the memory is freed when the last owner is destroyed.