You could make a static LookAndFeel inside of another class that isn’t static, for instance that’s possible to do for plugins by making the static LookAndFeel a member of the AudioProcessorEditor
There is actually a more clever way with LookAndFeel. You don’t create a static one, but you set one to the top level component, which can be a member there. Every child component will automatically use that lookAndFeel, unless a different one was set.
The algorithm works as follows:
if a LookAndFeel was set, use it
retrieve the parent’s LookAndFeel and use it
if it has no parent, use the defaultLookAndFeel, which is automatically set as a fallback.
Unfortunately there isn’t any. I once created a Component, that I added to the LookAndFeel, but unfortunately it’s not designed to be extended by anybody. You pick a number somewhere in high ranges, but there is always the danger for collisions later
FYI, for sharing a unique instance of a LookAndFeel and don’t incur in static initialization problems, I usually do something like this:
class MyCoolLookAndFeel : public LookAndFeel_V4
{
static MyCoolLookAndFeel& getInstance()
{
static MyCoolLookAndFeel instance;
return instance;
}
// here goes the usual implementation of the LnF
}
At that point, you can set the look and feel to the components that you want with
And this will ensure that the single instance will be created only upon first usage (i.e. avoiding the static initialization happening in undetermined order)