我在 xcode c++ 中找不到 allocator.destroy() 成员函数

问题描述 投票:0回答:1

我有一台 MacBook Air,我使用 Xcode 作为我的 IDE。当我编写下面的代码时,Xcode 显示一条警告,指出“std::allocator 中没有名为 destroy 和 construct 的成员”。然而,当我尝试在我的 Mac 上的 VS Code 中编译相同的代码时,它在没有任何警告的情况下成功构建。

#include <memory>

int main(){
    std::allocator<int> a;
    int* var = a.allocate(1);
    a.construct(var,10);
    a.destroy(var);
}

如果您希望我解决声明中的任何其他问题,请告诉我。

vscode result

xcode result

我想知道为什么 C++ 库在 IDE 之间不一致,因为我认为它应该是相同的。请帮助我,谢谢!

c++ xcode allocator
1个回答
1
投票

成员函数

construct
destroy
在 C++17 中被弃用,并在 C++20 中被删除。

假设您在 Xcode 中使用 C++20 编译器(因此这些成员函数不可用),而在 VS Code 中您使用的是旧标准。

© www.soinside.com 2019 - 2024. All rights reserved.