• C++主动调用析构函数


    #include <iostream>
    
    class Example {
    public:
        Example() {
            std::cout << "Default Example!" << std::endl;
        }
    
        Example(int id) : ID(id) {
            std::cout << "Example!" << std::endl;
        }
    
    
        virtual ~Example() {
            std::cout << "~Example:" << ID << std::endl;
        }
    
    private:
        int ID;
    };
    
    int main() {
        Example example(0);
        example.~Example();
        new(&example)Example(1);
        return 0;
    }
    
    
  • 相关阅读:
    20210131
    20210130
    20210129
    20210128
    20210127
    例3-7
    例3-5
    例3-4
    例3-3
    例3-2
  • 原文地址:https://www.cnblogs.com/iuyy/p/14280883.html
Copyright © 2020-2023  润新知