Edit: Anyone reading this in the future, there is a lot of tangential conversation in the posts below, so to summarize the solutions:
- per @daniel: Simply use curly brackets instead of regular brackets…
ReverbAudioSource reverb { &tone, false };
- per @PluginPenguin: Pass the parameters to the constructor in the initialisation list.
You guys are doing crazy stuff with scoped pointers, unique pointers, smart pointers etc. - all wizardry stuff which I’m sure never results in memory leaks meanwhile I way prefer to create stuff on the stack wherever possible (partly also because the world of heap allocation scares me)
I’m having trouble with the ReverbAudioSource class, because it needs in its constructor a pointer to an input source, and a bool.
So for example if my app wants to create a ToneGeneratorAudioSource object I create it the good old ‘on the stack’ way ToneGeneratorAudioSource tone;
If I want to use that as the input to a ReverbAudioSource object, this doesn’t work:
ToneGeneratorAudioSource tone;
ReverbAudioSource reverb(&tone, true):
(I’ve tried ReverbAudioSource(&tone, true) reverb;
also)
This is my current way of implementing a ToneGeneratorAudioSource and ReverbAudioSource (which I don’t like because when my app becomes more complex, I’ll have some sources on the stack and some will be on the heap, some variables will be passed with the address-of operator, some without and I’d have to mentally keep track of which, ugh):
class AudioApp
{
private:
AudioDeviceManager dm;
AudioSourcePlayer player;
ToneGeneratorAudioSource tone;
AudioSource* reverb = new ReverbAudioSource(&tone, true);
public:
AudioApp()
{
dm.initialiseWithDefaultDevices(0,1);
dm.addAudioCallback(&player);
player.setSource(reverb);
}
~AudioApp()
{
dm.removeAudioCallback(&player);
delete reverb;
}
};
In short, is there a way to have the ReverbAudioSource object instantiated on the stack, (and am I using a ‘correct’ philosophy to want to have it on the stack)