I have a main function that takes in a reference of a class object and try to update it via foo()
and bar()
, however, the bar()
only allows to pass into a shared_ptr type. How can I guarantee it behaves as expected, assuming I am allowed to modify the signature of bar()
.
void foo(MyStruct& s) {
modifyS(s);
}
void bar(std::shared_ptr<MyStruct> s) {
modifySAgain(s);
}
mainFunction(MyStruct& s) {
foo(s);
// bar(?) how should I do here such that s would be modified by bar()
// bar(std::make_shared<Mystruct>(std::move(s)) ?
}
Aucun commentaire:
Enregistrer un commentaire