class MyAudioProcessorEditor : public juce::AudioProcessorEditor, public juce::Slider::Listener, public juce::Button::Listener, public juce::ComboBox::Listener{
public:
MyAudioProcessorEditor (MyAudioProcessor&);
~MyAudioProcessorEditor() override;
void paint (juce::Graphics&) override;
void resized() override;
void sliderValueChanged(juce::Slider *slider) override;
void buttonClicked(juce::Button *button) override;
void comboBoxChanged(juce::ComboBox *comboBox) override;
void FillSettingsPanelWithValues();
void WriteToSettingsXML();
void ReadFromSettingsXML();
juce::ValueTree fullTree{"Fulltree"};
//If i write: juce::ValueTree fullTree("Fulltree"); it doesnt work
So the question is why do brackets not work inside header and why do curly brackets do work. And why do normal brackets work outside of the header in my cpp file :D
You have member-specification and parentheses () are ok only for member functions.
The {} are part of initializer for member variable within class definition.
In your "cpp file" you probably mean "within implementation of constructor" (or other function). That is a different scope and allows more initializer syntaxes.
In practical terms, the reason why you can't use () but can use {} in this context is just, that's how the syntax for C++ was laid out. They theoretically could have made it work in cases where it wasn't ambiguous with a function declaration, but it's just the way it is.
They theoretically could have made it work in cases where it wasn't ambiguous with a function declaration, but it's just the way it is.
It's already the case elsewhere.
Outside any class or inside a function, does
std::string foo();
1) declare a function that takes no arguments and returns a std::string, or
2) does it declare a variable of type std::string that is initialized using the default constructor?
The answer is 1, a function declaration. The rule is that if it can be interpreted as a function declaration then it will be. This is known as the "most vexing parse". https://en.wikipedia.org/wiki/Most_vexing_parse
class Sample {
int x {42};
int y(7); // error
};
int z(3);
y is direct initialization with params. This is allowed outside of a struct/class when it can't be parsed as a function declaration (as here). This is not allowed within a class/struct.
z is also direct initialisation with params. However as this is outside of a class/struct it compiles OK.
Simply (very!), anything that looks like a function declaration is tried to be parsed as a function declaration (most vexing parse). If that fails within a struct/class, then a compile error is generated. If that fails outside of a struct/class it is then tried to be parsed as an assignment. Having a value without a type specifier as a param cannot be a function declaration (which needs a type) - so fails in a struct/class but works outside!