• 尽量避免名字中出现数字编号


    尽量避免名字中出现数字编号,如 Value1,Value2 等,除非逻辑上的 确需要编号。

    这是为了防止程序员偷懒,不肯为命名动脑筋而导致产生无意义的名 字(因为用数字编号最省事)。

     1 #include <iostream>
     2 
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 using namespace std;
     5 //定义一个含有static数据成员的类
     6 class ex
     7 {
     8     static int num;      //static数据成员
     9 public:
    10     ex() {num++;}
    11     ~ex() {num--;}
    12     disp_count() {
    13        cout<<"The current instances count:";
    14        cout<<num<<endl;
    15     }
    16 };
    17 int ex::num=0;    //设置static数据成员的初值
    18 //main()函数测试ex类
    19 
    20 int main(int argc, char** argv) {
    21     ex a;
    22     a.disp_count();
    23 
    24     ex *p;
    25     p=new ex;
    26     p->disp_count();
    27 
    28     ex x[10];
    29     x[0].disp_count();
    30 
    31     delete p;
    32     a.disp_count();
    33     return 0;
    34 }
  • 相关阅读:
    VHDL硬件描述语言(三)——基本数据对象和数据类型
    VHDL硬件描述语言(二)——子程序
    VHDL硬件描述语言(一)——基本结构
    C#类
    C#基本语法
    C#的简单数据类型
    C#与.NET
    ARP
    IPv6
    以太网
  • 原文地址:https://www.cnblogs.com/borter/p/9413419.html
Copyright © 2020-2023  润新知