vendredi 11 novembre 2022

Why does "C++ allocator" show call stack error?

I am practicing with C++ allocator on MSVC from C++ primer example. It seems to be a call stack error, which I am not able to resolve. Here is the code, and with output image I am getting.

std::allocator<string> alloc;
constexpr size_t n = 10;        // Capacity

auto const p = alloc.allocate(n);
cout << "type id:   " << typeid(p).name() << endl;

string s;
auto q = p;
while (cin >> s && q != p + n)
{
    alloc.construct(q++, s);
}
const size_t sz = q - p;

for (auto pos = p; pos != q; ++pos)
{
    cout << *pos << endl;
}

while (q != p)
{
    alloc.destroy(--q);
}
alloc.deallocate(p, n);

Aucun commentaire:

Enregistrer un commentaire