没有运算符“=”匹配这些操作数,JUCE window 演示应用程序
no operator "=" matches these operands, JUCE window demo application
当我尝试从 This tutorial 编译演示文件时,出现 no operator "=" matches these operands
错误。我试过包括字符串(来自类似问题的建议),但这似乎没有意义,因为它应该已经包含在 JuceHeader.h
.
中
代码问题:
void initialise (const String& commandLine) override
{
// Add your application's initialisation code here..
mainWindow = new MainWindow (getApplicationName());
}
完整代码:
#include "../JuceLibraryCode/JuceHeader.h"
#include <string>
//==============================================================================
class MainWindowTutorialApplication : public JUCEApplication
{
public:
//==============================================================================
MainWindowTutorialApplication() {}
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
{
// Add your application's initialisation code here..
mainWindow = new MainWindow (getApplicationName());
}
void shutdown() override
{
// Add your application's shutdown code here..
mainWindow = nullptr;
}
//==============================================================================
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.
}
class MainWindow : public DocumentWindow
{
public:
MainWindow(String name) : DocumentWindow(name,
Colours::lightgrey,
DocumentWindow::allButtons)
{
centreWithSize(300, 200);
setVisible(true);
}
void closeButtonPressed() override
{
JUCEApplication::getInstance()->systemRequestedQuit();
}
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainWindow)
};
private:
std::unique_ptr<MainWindow> mainWindow;
};
//==============================================================================
// This macro generates the main() routine that launches the app.
START_JUCE_APPLICATION (MainWindowTutorialApplication)
编译器告诉您不能将指针分配给 unique_ptr
,这是真的:std::unique_ptr::operator=。您只能移动另一个 unique_ptr
或分配 nullptr
。有两种可能的解决方案:
mainWindow.reset(new MainWindow(getApplicationName()));
或
mainWindow = std::make_unique<MainWindow>(getApplicationName());
当我尝试从 This tutorial 编译演示文件时,出现 no operator "=" matches these operands
错误。我试过包括字符串(来自类似问题的建议),但这似乎没有意义,因为它应该已经包含在 JuceHeader.h
.
代码问题:
void initialise (const String& commandLine) override
{
// Add your application's initialisation code here..
mainWindow = new MainWindow (getApplicationName());
}
完整代码:
#include "../JuceLibraryCode/JuceHeader.h"
#include <string>
//==============================================================================
class MainWindowTutorialApplication : public JUCEApplication
{
public:
//==============================================================================
MainWindowTutorialApplication() {}
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
{
// Add your application's initialisation code here..
mainWindow = new MainWindow (getApplicationName());
}
void shutdown() override
{
// Add your application's shutdown code here..
mainWindow = nullptr;
}
//==============================================================================
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.
}
class MainWindow : public DocumentWindow
{
public:
MainWindow(String name) : DocumentWindow(name,
Colours::lightgrey,
DocumentWindow::allButtons)
{
centreWithSize(300, 200);
setVisible(true);
}
void closeButtonPressed() override
{
JUCEApplication::getInstance()->systemRequestedQuit();
}
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainWindow)
};
private:
std::unique_ptr<MainWindow> mainWindow;
};
//==============================================================================
// This macro generates the main() routine that launches the app.
START_JUCE_APPLICATION (MainWindowTutorialApplication)
编译器告诉您不能将指针分配给 unique_ptr
,这是真的:std::unique_ptr::operator=。您只能移动另一个 unique_ptr
或分配 nullptr
。有两种可能的解决方案:
mainWindow.reset(new MainWindow(getApplicationName()));
或
mainWindow = std::make_unique<MainWindow>(getApplicationName());