Button error [this declaration has no storage type]


#1

I'm getting an error with my button after trying to create a basic program..

here's my code

         

#ifndef MAINCOMPONENT_H_INCLUDED
#define MAINCOMPONENT_H_INCLUDED
#include "../JuceLibraryCode/JuceHeader.h"

//==============================================================================
/*
    This component lives inside our window, and this is where you should put all
    your controls and content.
*/
class MainContentComponent   : public Component
{
public:
    //==============================================================================
    MainContentComponent();
    ~MainContentComponent();
    
    void paint (Graphics&);
    void resized();
    button1 = new TextButton(("Button 1"));
    
private:
    //==============================================================================
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainContentComponent);
    TextButton button1;
    Slider slider1;
    Label label1;
};

#endif  // MAINCOMPONENT_H_INCLUDED


thanks in advance


#2

There are multiple issues with your code: first of all, the new operator will return a pointer to TextButton, which you trying to assign to a TextButton object directly. Also, you are doing the assignment (and calling new) outside of any function. You need to pull this into the constructor for example. See some of the example code in the example subfolder of JUCE.