相关疑难解决方法(0)

在销毁对象放置后没有调用析构函数 - new'ed

我不知道为什么这不起作用.以下Function内容由placement new创建.提供了一个函数,用于检查是否应该销毁它,如果是,则手动调用其析构函数.

这是测试用例,似乎从不调用析构函数:

/* Represents a function at runtime */ 
class Function {
public:
  /* Creates an invalid function */
  Function():codeptr(0) { }

  /* Creates a function with the given code pointer */
  Function(void *codeptr):codeptr(codeptr) { }

  /* Frees the function machine code */
  ~Function() {
    if(*this) {
      /* <- I explicitly put a debug output here! */
      destroyLLVMCode(codeptr);
    }
  }

public:
  /* Returns true if the function is valid 
   * (if the code pointer is non-null)
   */ …
Run Code Online (Sandbox Code Playgroud)

c++ destructor placement-new

13
推荐指数
2
解决办法
907
查看次数

标签 统计

c++ ×1

destructor ×1

placement-new ×1