zoukankan      html  css  js  c++  java
  • 构造函数的调用(其中不包括赋值构造函数)

     1 #include<iostream>
     2 
     3 using namespace std;
     4 //解析和析构函数的调用
     5 class Test
     6 {
     7 public:
     8     Test()
     9     {
    10         cout<<"我是无参的构造函数
    
    ";
    11     }
    12     Test (int i)
    13     {
    14         t_a=i;
    15         cout<<"i= "<<i<<endl;
    16         cout<<"哎呀,人家是形参为1的构造函数、
    
    ";
    17     }
    18     Test (int a,int b)
    19     {
    20         cout<<"a= "<<a<<" b= "<<a<<endl;
    21         cout<<"我是两个参数的构造函数、
    
    ";
    22     }
    23     Test(const Test &obj)
    24     {
    25         cout<<"我是赋值构造函数又叫拷贝构造函数
    
    ";
    26     }
    27     ~Test()
    28 
    29     {
    30         cout<<"我是析构函数
    
    ";
    31     }
    32 
    33 private:
    34     int t_a;
    35     int t_b;
    36 protected:
    37 };
    38 int main()
    39 {
    40     cout<<"Test t1  ====>";
    41     Test t1;//无参函数的赋值
    42     cout<<endl;
    43     cout<<"Test t2(1,3) =========>";
    44     Test t2(1,3);//两个形参的函数调用
    45     cout<<endl;
    46 
    47     cout<<"Test t3=(1,3)========>";
    48     Test t3=(1,3);//一个形参的调用
    49     cout<<endl;
    50     cout<<"Test t4=3========>";
    51     Test t4=3;//一个形参的调用
    52     cout<<endl;
    53     cout<<"Test t5(3)========>";
    54     Test t5(3);//一个形参的调用
    55     cout<<endl;
    56 
    57     cout<<"Test t6=Test(1)========>";
    58     Test t6=Test(1);//匿名对象,这个较为特殊,右边括号内几个值就调用几个形参的函数。
    59     cout<<endl;
    60 
    61     cout<<"Test t7=Test(1,3)========>";
    62     Test t7=Test(1,3);//匿名对象,这个较为特殊,右边括号内几个值就调用几个形参的函数。
    63     cout<<endl;
    64 
    65 
    66     cout<<" hello world 
    ";
    67     system("pause");
    68 }

  • 相关阅读:
    HTML5表单
    jQuery Mobile组件
    HTML5新增加的功能
    jQuery Mobile基础
    【android】两个按钮的宽度各占屏幕的一半
    AndroidUI--SlidingMenu使用例子
    android之PackageManager简介
    AlarmManager类的应用
    AlarmManager类的应用(实现闹钟功能)
    laravel 控制器内使用切换数据库
  • 原文地址:https://www.cnblogs.com/xiaochige/p/6561574.html
Copyright © 2011-2022 走看看