c++iosmobilejuce

Getting an error "allocating an object of abstract class type in Juce Framework?


i am new in juce and getting an error like "allocating an object of abstract class type 'CreateAccount'" i am beginner in c++. i am try to call the class from the main window of juce and getting error like this.Below is my code

Main.cpp file

#include <JuceHeader.h>
#include "CreateAccount.h"

//==============================================================================
class TestApplication  : public JUCEApplication
{
public:
    //==============================================================================
    TestApplication() {
    }

    const String getApplicationName() override  {
        return "Test";
    }
    const String getApplicationVersion() override    { return "1.0.0"; }

    void initialise (const String&) override         {
        mainWindow.reset (new MainWindow ("Test", new CreateAccount(), *this));
     //  splash = new SplashScreen("Welcome to Screen!",ImageFileFormat::loadFrom(File("/Resources/bell.png")),
                             //    true);

       // splash->deleteAfterDelay(RelativeTime::seconds(5), false);
    }

       void shutdown() override {
        mainWindow = nullptr;
    }

private:
    class MainWindow    : public DocumentWindow
    {
    public:
        MainWindow (const String& name, Component* c, JUCEApplication& a)
                : DocumentWindow (name, Desktop::getInstance().getDefaultLookAndFeel()
                                          .findColour (ResizableWindow::backgroundColourId),
                                  DocumentWindow::allButtons),
                  app (a)
        {
            setUsingNativeTitleBar (true);
            setContentOwned (c, true);

#if JUCE_ANDROID || JUCE_IOS
            setFullScreen (true);
#else
            setResizable (true, false);
            setResizeLimits (300, 250, 10000, 10000);
            centreWithSize (getWidth(), getHeight());
#endif

            setVisible (true);
        }

        void closeButtonPressed() override
        {
            app.systemRequestedQuit();
        }


    private:
        JUCEApplication& app;


        //==============================================================================
        JUCE_DECLARE_NON_COPYABLE (MainWindow)
    };

    std::unique_ptr<MainWindow> mainWindow;


};

//==============================================================================
START_JUCE_APPLICATION (TestApplication)

CreateAccount.h file

#include <JuceHeader.h>

//new page for create profile
class CreateAccount : public Component,
                        public Button::Listener

        {
public:
    CreateAccount() {

        addAndMakeVisible(lblloginwithfb);
        lblloginwithfb.setFont(Font(18.0f));
        lblloginwithfb.setText("Login with Facebook", dontSendNotification);
        lblloginwithfb.setColour(Label::textColourId, Colours::white);

        //ready to play button
        btncreteprofile.setButtonText("Create your profile");
        btncreteprofile.setColour(TextButton::textColourOffId, Colours::white);
        btncreteprofile.setColour(TextButton::textColourOnId, Colours::white);
        btncreteprofile.setColour(TextButton::buttonColourId,  Colour::fromRGB(235,135,15));
        btncreteprofile.setColour(TextButton::buttonOnColourId, Colour::fromRGB(235,135,15));
        addAndMakeVisible(btncreteprofile);

    }
    //==============================================================================
    void paint(Graphics &g) override {
        g.fillAll(Colours::black);
    }

    void resized() override {

        /*Rectangle<int> bounds = getLocalBounds();
        FlexBox flexBox;

        flexBox.flexDirection = FlexBox::Direction::column;
        flexBox.flexWrap = FlexBox::Wrap ::noWrap;
        flexBox.alignContent = FlexBox::AlignContent::center;

        Array<FlexItem> itemarray;
        itemarray.add(FlexItem(80,50,btncreteprofile));
        itemarray.add(FlexItem(getWidth(),50,lblloginwithfb));


        flexBox.items = itemarray;
        flexBox.performLayout(bounds.removeFromBottom(200));*/
        Rectangle<int> bounds = getLocalBounds();
        const int insetX = getWidth() / 4;
        const int insetY = getHeight() / 4;


        btncreteprofile.setBounds(insetX,bounds.getCentre().y+80,getWidth() - insetX * 2, 50);
        lblloginwithfb.setBounds(insetX,insetY,getWidth() - insetX * 2,getHeight());

    }

private:
    //==============================================================================
    // Your private member variables go here...
    Label lblloginwithfb;
    TextButton btncreteprofile;

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CreateAccount)
};

Please help me when i try to add the listner in createaccount file then will get an error.


Solution

  • You need to implement all pure virtual methods in Button::Listener to make your class not abstract. Button::Listener contains these two methods

    virtual void    buttonClicked (Button *)=0
    virtual void    buttonStateChanged (Button *)
    

    The second method is not pure virtual, so you don't have to implement it.

    So add a method to your class

    virtual void    buttonClicked (Button *) override {}
    

    and add the code needed when the button is clicked.

    Depending on the C++ version you're using, the override might not get accepted by the compiler. In that case, just omit it. It is used to allow the compiler to emit warnings/errors with respect to overridden methods.