Initializing variables in the constructor, "Create Midi data" tutorial

Howdy, I’m working through the “create midi data” tutorial, here: https://docs.juce.com/master/tutorial_midi_message.html

After it says to " Add some members to our MainContentComponent class", it also says " We need to initialise the sampleRate and previousSampleNumber members in our MainContentComponent constructor" and shows

MainContentComponent()
: startTime (Time::getMillisecondCounterHiRes() * 0.001)
{
//…

I’m confused by that second part. Are they not already initialized when the object is created, since they are given values in their declaration? What would I do to initialize them in the constructor? Just set them to those same values?

I noticed that the second header file included with the tutorial (the one that’s supposed to be completed) doesn’t have anything added to the constructor except for “startTimer(1);”, which is discussed later in the tutorial it looks like.

I’m guessing I’m missing something obvious, admittedly I’m not very familiar with C++ yet. (I know some Java, and am basically learning C++ as I learn JUCE.) Could someone point out what it is I don’t understand? (Feel free to link me to any sources/materials if that’s easier.)

Thanks for any help!

It looks like an error in the tutorial. If the members were already initialized in the class declaration, there of course is no need to initialize them again in the constructor. (Unless there’s a possibility to initialize them in some other way in the constructor. It would still make sense to initialize them to some valid values in the class declaration. C++ does not default initialize variables to zeros .)

Thanks, that’s a relief xD Do you know if there’s somewhere I should report the error?

The JUCE team monitors the forum for bug reports.

We’ll get this updated. Thanks for reporting!