"Thinkinginc++" 65, using delete void* may be an error

Source: Internet
Author: User
/*** book: "thinkinginc++" * Function: Use delete void* may error * Time: October 5, 2014 14:31:43* Author: cutter_point*/#include <iostream> Using namespace Std;class object{    void* data;//a void* type pointer    const int size;    const char Id;public:    Object (int sz, char c): Size (SZ), ID (c)    {        data=new char[size];        cout<< "Create a Class" <<id<< ", size =" <<size<<endl;    }    destructor, output a paragraph of the execution of the destructor, and then the destructor data array    ~object () {cout<< "destruction of this class" <<id<<endl; delete [] data;}; int main () {    object* a=new Object (+, ' a ');    Delete A;    void* b=new Object (+, ' B ');    Delete B;   The result of the display is that B does not call the destructor    //Because it does not know what type B is, then the result of the program execution is that the object memory of B is recycled, but the    class content within//class is not destructor,    return 0;}

"Thinkinginc++" 65, using delete void* may be an error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.