Mooophy / Cpp-Primer

C++ Primer 5 answers
Creative Commons Zero v1.0 Universal
8.06k stars 3k forks source link

Ex13.42 #830

Open Cyitao opened 1 year ago

Cyitao commented 1 year ago

std::allocator alloc should be defined as static variable;

amritpalsingh52 commented 1 year ago

The std::allocator is used as a temporary object in this example to allocate memory for a single std::string object. It is instantiated within the main function and goes out of scope when the function returns.

If you want to use the std::allocator in a global context and keep it alive throughout the program's lifetime, you can define it as a static variable inside a class or a global variable: