Returns a raw pointer or reference to the object that it points to. When an object matters std::unique_ptr, it indicates ownership. Meaning, an object containing a pointer will allocate and also delete allocated resources when they like it.
For instance:
class Car {
public:
Engine* getEngine() const { return engine_.get(); }
private:
std::unique_ptr<Engine> engine_;
}
You can ask for a car, perhaps an available engine, you should always assume that it may not be, but you should not free it, it is not yours, it belongs to the car.
source
share