zoukankan      html  css  js  c++  java
  • C++_练习—构造与析构

    构造与析构


     1 #include <iostream>
     2 
     3 using namespace std;
     4 
     5 class info {
     6 public:
     7     info(int a);
     8     info(int a, int b);
     9     info(int a,int b,int c);
    10 
    11     ~info();  // 无类型无返无参
    12 
    13 private:
    14     int age;
    15     int *temp;
    16 };
    17 
    18 
    19 info::info(int a) {
    20     cout << a << endl;
    21     temp = new int;
    22 }
    23 
    24 info::info(int a, int b) {
    25     cout << a << b << endl;
    26     temp = new int;
    27 
    28 }
    29 
    30 info::info(int a, int b, int c) {
    31     cout << a << b << c << endl;
    32     temp = new int;
    33 }
    34 
    35 
    36 info::~info() {
    37     delete temp;
    38     cout << "析构函数,系统调用,释放空间" << endl;
    39 }
    40 
    41 
    42 int main(void) {
    43 
    44     info info1(7);
    45 
    46     cout << "end" << endl;
    47 
    48 //    info1.~info();
    49 
    50     system("pause");
    51 
    52 
    53     return 0;
    54 }

    Stay hungry, stay foolish 待续。。。
  • 相关阅读:
    jQuery(2)
    jQuery(1)
    underscore.js
    面向对象复习
    1.14函数复习
    面向对象(3)继承
    10.18
    1017
    js笔记二
    js笔记一
  • 原文地址:https://www.cnblogs.com/panda-w/p/11356398.html
Copyright © 2011-2022 走看看