131. Ownership

Question.4

A factory creates a driver and transfers ownership to a manager:

std::unique_ptr<IDriver> create_driver(int type) {
   if (type == 1) return std::make_unique<UART>();
   return std::make_unique<SPI>();
}

class Manager {
   std::unique_ptr<IDriver> drv;
public:
   Manager(std::unique_ptr<IDriver> d)
       : drv(std::move(d)) {}
};

auto d = create_driver(1);
Manager mgr(std::move(d));

After the last line, who owns the driver?

Need Help? Refer to the Quick Guide below

Select Answer