So I noticed in the Main.cpp that ScopedPointer mainWindow; changed to std::unique_ptr mainWindow; Coming from a C# I have been contented just using new and delete concept as this made sense to me (I have been bitten a few times with the sequencencing when destroying and access violations on threads). Reading the roadmap saying that juce library wants to replace out ScopedPointer in favour of the standard libraries unique_ptr is this the correct way of using in a juce context or is there going to be a different way?
If this object has a default constructor, then why use a pointer at all? Unless you actually need it to be a pointer, just using a member variable is by far the best way of handling object lifetimes.
Cheers, yeah I usually do that with controls such as knobs, sliders, buttons e.t.c. but I do find it handier to have things like scenes to be pointers as I have an extended component class with a few extra methods for passing info and events between. Just checking that I wasn’t doing anything stupid if I did it that way?
addAndMakeVisible takes references and pointers. imo, the syntax for pointer dereferencing is super ugly, so I avoid it as much as possible, unless absolutely required.
Personally I would prefer the addAndMakeVisible (Component&) overload because it’s slightly more efficient but also clearer if you know the object is valid.
Personally I often do: addAndMakeVisible (*(header = std::make_unique<Header>()))
but I’m aware that’s a little parenthesis heavy.
Jule’s suggestion or even a templated pointer version could work?