首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JUCE:无法实例化类"operate '=‘to Not match the operand“

JUCE:无法实例化类"operate '=‘to Not match the operand“
EN

Stack Overflow用户
提问于 2018-11-19 01:30:16
回答 1查看 58关注 0票数 1

我正在努力使用JUCE库,因为我正在遵循GUI教程,并且出于某种原因,我不能在初始化函数中使用"new instance“语法。对于这个特定的代码块,是否有什么上下文特定的东西不允许使用"new“操作符来实例化GUI窗口类?

代码语言:javascript
复制
 #include "../JuceLibraryCode/JuceHeader.h"
    #include "MainComponent.h"
    #include <iostream>

    /* Auto generated code*/

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

        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
        {


            MyWindow.reset (new The_Main_Window (getApplicationName()));

            MyWindow = new The_Main_Window(getApplicationName()); //New instance syntax. 
        }

        void shutdown() override
        {
            // Add your application's shutdown code here..

            MyWindow = nullptr; // (deletes our window)
        }

        //==============================================================================
        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 class implements the desktop window that contains an instance of
            our MainComponent class.
        */
        class The_Main_Window    : public DialogWindow
        {
        public:
            The_Main_Window (String name) : DialogWindow (name, Colours::beige,DialogWindow::allButtons)

            {
                setUsingNativeTitleBar (true);
                setContentOwned (new MainComponent(), true);
                setResizable (true, true);

                centreWithSize (300, 600);
                setVisible (true);
            }

            void closeButtonPressed() override
            {

                JUCEApplication::getInstance()->systemRequestedQuit();
            }



        private:
            JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (The_Main_Window)
        };

    private:
        std::unique_ptr<The_Main_Window> MyWindow; // what the heck does this guy do? 
    };

    //==============================================================================
    // This macro generates the main() routine that launches the app.
    START_JUCE_APPLICATION (MyApplication) // This guy generates the entry point?
EN

回答 1

Stack Overflow用户

发布于 2018-11-19 01:45:01

唯一指针没有新指针的赋值运算符(https://en.cppreference.com/w/cpp/memory/unique_ptr/operator=)。为此,您需要reset

不管怎样,你做了两次同样的事情,第二次是多余的(有赋值的那次)。

代码语言:javascript
复制
void initialise (const String& commandLine) override
{
    MyWindow.reset (new The_Main_Window (getApplicationName()));
}

关机也是如此:

代码语言:javascript
复制
void shutdown() override
{
    // Add your application's shutdown code here..

    MyWindow.reset(); // (deletes our window)
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53363653

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档