How to explicitly call a namespace-qualified destructor?

前端 未结 2 1769
野趣味
野趣味 2021-01-03 20:04

I am surprised that the following simple code won\'t compile (with gcc, version 4.8.1)

#include 
void test()
{
  std::string* p = new std::stri         


        
2条回答
  •  -上瘾入骨i
    2021-01-03 20:12

    2019 update: Starting from C++17, you can use std::destroy_at as follows:

    std::destroy_at(p);
    

    It's much simpler and follows the principle of not using "primitive constructs" (such as new / delete expressions) in modern C++.

提交回复
热议问题