zoukankan      html  css  js  c++  java
  • 构造函数与析构函数的程序

     1 #include <string.h>
     2 #include <iostream>
     3 
     4 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     5 using namespace std;
     6 
     7 class Student
     8 {
     9     public:
    10         Student(int n,string name,char s)
    11         {
    12             num=n;
    13             na=name;
    14             sex=s;
    15             cout<<"Constructor called."<<endl;
    16         }
    17         ~Student()
    18         {
    19             cout<<"Destructor called."<<endl;
    20         }
    21         void display()
    22         {
    23             cout<<"num:"<<num<<endl;
    24             cout<<"name:"<<na<<endl;
    25             cout<<"sex:"<<sex<<endl;
    26         }
    27         private:
    28             int num;
    29             string na;
    30             char sex;
    31 };
    32 
    33 int main(int argc, char** argv) {
    34     Student stud1(10010,"Wang_li",'f');
    35     stud1.display();
    36     Student stud2(10011,"Zhang_fun",'m');
    37     stud2.display();
    38     return 0;
    39 }
  • 相关阅读:
    01-节点层次
    WebAPI02
    WebAPI01
    牛客剑指Offer7
    Python字典排序
    Python字典中的键映射多个值
    计算机硬件的主要技术指标
    计算机的基本组成
    计算机系统概论
    数据库概论
  • 原文地址:https://www.cnblogs.com/borter/p/9401892.html
Copyright © 2011-2022 走看看