C++ Question from DSP Tutorial

I’ve been working through the JUCE DSP tutorial and came across this line:

auto &osc = processorChain.template get<oscIndex>();

From what I gather, I think this line gets a pointer to an oscillator object that we can then work with.
I’m confused about what the purpose of the ‘template’ keyword is.

1 Like

With some compilers it should work without the template keyword.
As far as I know this way you tell the compiler that the following method is a template, and you will provide a template argument within the <>. Otherwise the compiler could assume that get is a member variable and you want to check if it’s smaller (<) than oscIndex.

1 Like

Small note: auto& osc shows that it’s not a pointer but a reference that is returned here. If you are coming from plain C, where a pointer would be the obvious choice in such a context, I would advise you to have a quick read on references and why they are preferred over pointers in many cases when working with C++ :wink:

If you are coming from plain C, where a pointer would be the obvious choice in such a context

Yup! Guilty as charged. I am trying to catch up on C++. Appreciate the tip :slight_smile: