I have a struct as a class member variable, and in a method I need to pass a TSharedPtr to this member variable to a routine. How can I do this without the TSharedPtr, when it goes out of scope, attempting to destroy the member?
In the example below, when ExMethod completes, it will free ExStructVar.
class ExClass {
public:
void ExMethod() {
TSharedPtr<ExStruct> ExStructVarPtr = MakeShareable(&this->ExStructVar);
SomeRoutine(ExStructVarPtr);
}
ExStruct ExStructVar;
};
Can I bump the ref count up somehow?
P.S. This example is contrived. In the real world, I can’t change the declaration of ExStructVar, or the signature of SomeRoutine.