Can't access private or protected members from SafePointer?

When you declare a SafePointer to a Component, to use in Asynchronous callbacks, should you be able to access private and protected members from it?

It doesn’t seem to be working for me.

I even tried adding a friend class to the base class:

friend SafePointer<MainComponent>;

I think I must be doing something wrong with this one; I can’t recall ever having this problem before…

I think this is correct, since the SafePointer is owned by the std::function, not this.

What could work is using the SafePointer to check and early exit, but use subsequently this:

SafePointer<MainComponent> safe (this);
juce::Timer::callAfterDelay (5000, [this, safe]
{
    if (!safe)
        return;

    doPrivateStuff();
});

Haven’t tested…

2 Likes

yes, I have used that before, I just thought that I had also accessed private or protected variables through the SafePointer before. Maybe not.