zoukankan      html  css  js  c++  java
  • 【求解】未定义的析构函数

    abc说明:定义 del 函数的时候,abc 的析构函数未定义,因此不会调用。看如下代码,试解释器运行结果

    #include <stdio.h>
    class abc;
    void del(abc *pobj)
    {
    delete pobj;

    }
    class abc{
    public:
    abc()
    {
    printf(
    "abc\r\n");
    }
    ~abc()
    {
    printf(
    "~abc\r\n");
    }
    };
    int main(int argc, char *argv[])
    {
    abc
    *pobj = new abc;
    del(pobj);
    return 0;
    }

     编译出现警告

    C:\Users\Ares\Desktop>g++ test.cpp
    test.cpp: In function `
    void del(abc*)':
    test.cpp:5: warning: possible problem detected in invocation of delete operator:
    test.cpp:
    4: warning: `pobj' has incomplete type
    test.cpp:2: warning: forward declaration of `struct abc'
    test.cpp:5: note: neither the destructor nor the class-specific operator delete
    will be called, even
    if they are declared when the class is defined.
    test.cpp:
    27:2: warning: no newline at end of file

      abc

    说明:定义 del 函数的时候,abc 的析构函数未定义,因此不会调用。感觉有说服力么?

  • 相关阅读:
    python IDE安装-mac
    tokudb引擎安装-2
    MariaDB10.2.X-新特性2-支持check约束and with as
    MariaDB10.2.X-新特性1-支持分析函数
    MySQL5.7表空间加密
    MySQL 5.7 SYS scheme解析
    tcpdump抓SQL
    pt-online-schema-change
    查看锁信息
    onlineDDL测试
  • 原文地址:https://www.cnblogs.com/westfly/p/2177259.html
Copyright © 2011-2022 走看看