C++ 使用未声明的标识符'make_unique'

C++ Use of undeclared identifier 'make_unique'

本文关键字:unique make 标识符 未声明 C++      更新时间:2023-10-16

我在构建时不断收到以下错误

使用未声明的标识符"make_unique"m_planet=make_unique();

我的头文件,它给出了错误,

#include "planet.h"
#include <memory>
using namespace std;
class PlanetBuilder
{
public:
    PlanetBuilder();
    virtual ~PlanetBuilder();
    void createNewPlanetProduct() {
        m_planet = make_unique<Planet>();
    }
protected:
    unique_ptr<Planet> m_planet;
};
#endif // PLANETBUILDER_H

我正在运行QtCreator 3.6.0,在Mac和Windows平台上都尝试过,错误是一致的。。我哪里错了?

make_unique需要#include <memory>但既然你已经这样做了,我认为你没有使用C++14或更高版本。尝试在make文件中添加以下标志。

-std=c++14

对于5.7的当前QT,我使用#include。通过以下链接,您可以了解更多信息。QScopedPointer链接