c++ 类中常量成员,和引用成员初始化

来源:互联网 发布:js setinterval用法 编辑:程序博客网 时间:2024/04/29 06:33

/*******************************************************
 *author:彭晓林
 *copyright: 版权所有,翻版不究
 *function: 类成员常量和引用的初始化示例
 ******************************************************/

#include <iostream>
#include <string>

using namespace std;

class DEMO

 public:
  DEMO (int a, int b):x(1), y(z), z(b)
  {
   cout<<"构造函数被调用:/n";
   cout<<"x = "<< x<<endl;
   cout<<"y = "<< y <<endl; 
   cout<<"z = "<< z <<endl; 
  }
 private:
  const int x;
  int z;
  int &y;
};


int main()
{
 DEMO *p = new DEMO(1,2);

 delete p;

 while(1);
}

原创粉丝点击