Is there any reason i can’t declare WeakReference<Label>
?
Since label is a Component, we should be able to have a WeakReference on the derived class.
At the moment i need to declare it using the base class (because the Master is private):
WeakReference<Component> x = label;
so i’m forced to do ugly casts and gets later in the code.
Label* label = static_cast<Label*>(x.get());
Any possibility to improve this ?
Have not tried it myself, but maybe this would work?
Didn’t know about that one. What are the differences with the WeakReference?
yfede
October 23, 2020, 9:44am
4
Component::SafePointer has the same issue (at least in JUCE 5, haven’t checked in 6 yet)
LiamG
October 23, 2020, 5:13pm
5
They’re basically the same. SafePointer
just wraps a WeakReference
and adds a couple of extra methods getComponent()
and deleteAndZero()
.
I thought it could work because SafePointer holds a WeakReference<Component>
, but SafePointer::getComponent() returns ComponentType* (literally return dynamic_cast<ComponentType*> (weakRef.get())
) -maybe I’m misunderstanding the issue.
Yeah SafePointer::getComponent() should work. thanks !