It seems an easy way to circumvent a unique_ptr
is to use a pointer to the unique_ptr
object. And that's not difficult. So using the unique_ptr is sort of a gentleman's agreement and not really super enforced?
#include <iostream>
#include <memory>
using namespace std;
class Box {
public:
int num;
};
void update_box(unique_ptr<Box>* pu);
int main(){
unique_ptr<Box> b{new Box};
unique_ptr<Box>* u = &b;
update_box(u);
cout << b->num << endl; // Outputs 99.
return 0;
}
void update_box(unique_ptr<Box>* pu) {
(*pu)->num = 99;
}