Search code examples
c++xcodeallocator

i can't find the allocator.destroy() member function in xcode c++


I have a MacBook Air and I'm using Xcode as my IDE. When I write the code below, Xcode shows a warning that says "no member named destroy and construct in std::allocator<int>". However, when I try to compile the same code in VS Code on my Mac, it builds successfully without any warnings.

#include <memory>

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

Please let me know if there are any other issues with the statement that you would like me to address.

vscode result

xcode result

I'm wondering why the C++ library is not consistent across IDEs, since I assumed it should be the same. Please help me with it, thank you!


I changed the C++ language dialect to C++11, and that solved the problem. solution


Solution

  • The member functions construct and destroy were deprecated in C++17 and removed in C++20.

    Presumably you're using a C++20 compiler in Xcode (hence those member functions are not available) while in VS Code you're using an older standard.