C++ 构造函数constructor 与 析构函数destructor 的区别

来源:互联网 发布:java进程和线程的区别 编辑:程序博客网 时间:2024/06/15 11:27

  构造函数constructor析构函数destructor1目的purpose初始化一个类实例constructor is used to initialize the instance of a class摧毁实例对象,释放资源.destructor destroys the objects when they are no longer needed2何时调用when called创建类实例时调用constructor is called when new instance of a class is created类实例被删除时destructor is called when instance of a class is deleted or released3内存管理memory management开辟内存空间constructor allocates the memory释放内存空间 destructor releases the memory4形参parameters可以有形参constructor can have parameters不允许有形参destructor can not have any parameters5重载overloading允许重载overloading of constructor is possible不允许重载overloading of destructor is not possible6函数名name和类的名字一致constructor have the same name as class name和类的名字一致,但前面要有~符号.destructor also have the same name as class name, but with(~) tiled operator

0 0
原创粉丝点击