C++ question. Please be detail if you can. Thank you verymuch.
a/Write code to keep the object which obj owns alive outside ofthe scope of func and wPtr reference obj.
b/Write code to test if wPtr is dangling. Is itdangling ornot?
class Name {
public:
Name() {}
private:
string name{ “CS” };
};
weak_ptr<Name> wPtr;
share_ptr<Name> sPtr{nullptr};
void func() {
unique_ptr<Name> obj { make_unique<Name>() };
// #1 Insert Code
}
int main() {
// #2 Insert Code
return 0;
}
Expert Answer
An answer will be send to you shortly. . . . .