Errors when compiling code taught during Tutorials

tutorials

#1

Hello world!
I’m new to Juce and starting to give up on it already with these tutorials always giving me errors. I am doing EXACTLY step by step what the tutorials have told me and when i compile it on XCode the build fails. I’m going to start with this example from tutorial:
https://docs.juce.com/master/tutorial_main_window.html

Here is the code that i have:

#include "../JuceLibraryCode/JuceHeader.h"

//==============================================================================
class MainWindowTutorialApplication : public JUCEApplication
{
public:
//==============================================================================
class MainWindow : public DocumentWindow
{
public:
MainWindow (String name) : DocumentWindow (name,
Colours::lightgrey,
DocumentWindow::allButtons)
{
centreWithSize (300, 200);
setVisible (true);
}
void closeButtonPressed() override
{
JUCEApplication::getInstance()->systemRequestedQuit();
}
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
};
private:
ScopedPointer mainWindow;
};

MainWindowTutorialApplication() {}

const String getApplicationName() override       { return ProjectInfo::projectName; }
const String getApplicationVersion() override    { return ProjectInfo::versionString; }
bool moreThanOneInstanceAllowed() override       { return true; }

//==============================================================================
void initialise (const String& commandLine) override
{
    // Add your application's initialisation code here..
    mainWindow = new MainWindow (getApplicationName());

}

void shutdown() override
{
    // Add your application's shutdown code here..
    mainWindow = nullptr;
}

//==============================================================================
void systemRequestedQuit() override
{
    // This is called when the app is being asked to quit: you can ignore this
    // request and let the app carry on running, or call quit() to allow the app to close.
    quit();
}

void anotherInstanceStarted (const String& commandLine) override
{
    // When another instance of the app is launched while this one is running,
    // this method is invoked, and the commandLine parameter tells you what
    // the other instance's command-line arguments were.
}

};

//==============================================================================
// This macro generates the main() routine that launches the app.
START_JUCE_APPLICATION (MainWindowTutorialApplication)

The error I have is:
MainWindowTutorialApplication() {} — Expected unqualified i-d
const String getApplicationName() override { return ProjectInfo::projectName; } — Expected function body after function declarator
START_JUCE_APPLICATION (MainWindowTutorialApplication) – Allocating an object of abstract class type 'MainWindowTutorialApplication’_

I’ve tried moving these codes around to make sure it wasn’t a matter of things being in the wrong order, didn’t work and generate even more errors. This is the 3rd tutorial I try to do and all I get is errors. Some other tutorials that I did on other websites worked, so it’s not just me. I think the tutorials are missing steps and when you name as it “Beginner Level” you can’t just infer that the beginner will just fill in those gaps.


#2

It’s a bit difficult to tell because of the text formatting in your post, but it looks like you didn’t add those methods like getApplicationName inside the MainWindowTutorialApplication class.

It could be useful if the tutorials had the correct source codes available for each step of the tutorial. Not embedded in the tutorial text of course because that would defeat the purpose of having the tutorials, but maybe as links one could check in case it turns out the code just won’t work.


#3

Maybe things just got jumbled up when you copied the code here but it looks like your code isn’t even syntactically correct.

#include "../JuceLibraryCode/JuceHeader.h"

//==============================================================================
class MainWindowTutorialApplication : public JUCEApplication
{
public:
    //==============================================================================
    class MainWindow : public DocumentWindow
    {
    public:
        MainWindow (String name) : DocumentWindow (name,
                                                   Colours::lightgrey,
                                                   DocumentWindow::allButtons)
        {
            centreWithSize (300, 200);
            setVisible (true);
        }
            void closeButtonPressed() override
        {
        JUCEApplication::getInstance()->systemRequestedQuit();
        }
    private:
        JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
    };

private:
    ScopedPointer mainWindow;
};

Up to this point you seem to be okay, everything after this just seems to be floating about?

MainWindowTutorialApplication() {}

const String getApplicationName() override       { return ProjectInfo::projectName; }
const String getApplicationVersion() override    { return ProjectInfo::versionString; }
bool moreThanOneInstanceAllowed() override       { return true; }

//==============================================================================
void initialise (const String& commandLine) override
{
    // Add your application's initialisation code here..
    mainWindow = new MainWindow (getApplicationName());
}

void shutdown() override
{
    // Add your application's shutdown code here..
    mainWindow = nullptr;
}

//==============================================================================
void systemRequestedQuit() override
{
    // This is called when the app is being asked to quit: you can ignore this
    // request and let the app carry on running, or call quit() to allow the app to close.
    quit();
}

void anotherInstanceStarted (const String& commandLine) override
{
    // When another instance of the app is launched while this one is running,
    // this method is invoked, and the commandLine parameter tells you what
    // the other instance's command-line arguments were.
}
}; // <- Why is this here?

//==============================================================================
// This macro generates the main() routine that launches the app.
    START_JUCE_APPLICATION (MainWindowTutorialApplication)

#4

Good spot @Im_Jimmi, but it is the other one to point to:

initialise, shutdown, systemRequestedQuit and anotherInstanceStarted are methods of your MainWindowTutorialApplication class. But you closed the classes namespace after the ScopedPointer mainWindow; line…