简体   繁体   中英

C++: “incomplete type is not allowed” when declaring an object - What is the cause?

The following code was provided to me by one of the JUCE admins, and on his Mac he says it is working, but for me, I get "incomplete type is not allowed" on the object declarations in "Private".

I cannot understand the cause of the error.

class LabeledSlider : public GroupComponent

{
    public:
    LabeledSlider (const String& name)
    {
        setText (name);
        setTextLabelPosition (Justification::centredTop);
        addAndMakeVisible (slider);
    }

    void resized() override
    {
        slider.setBounds (getLocalBounds().reduced (10));
    }

    Slider slider 
    { 
        Slider::RotaryHorizontalVerticalDrag, Slider::TextBoxBelow 
    };

 private:
    LabeledSlider frequency { "Frequency" };
    LabeledSlider level { "Level" };

};

Screencap of Visual Studio Error

My Visual Studio Community 2017 is fully up to date, so I'm not sure why it works for him and not me.

What would be the issue here? How do I fix it?

Please if you know the fix be specific or really clear about what you mean

Thanks guys. You helped me figure it out.

"An object cannot contain itself, that would be infinite recursion."

Like I said I'm new to this stuff so that's not common sense to me though now I get it.

I was supposed to put this part:

 private:
    LabeledSlider frequency { "Frequency" };
    LabeledSlider level { "Level" };

Outside the class declaration in the part of the synth app where the other objects were defined during the synth's actual coding part "MainContentComponent" where the magic happens.

Moved it there and it works now.

Sorry for dumb question. Thanks for clarification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM