zoukankan      html  css  js  c++  java
  • 类名和函数名用大写字母开头的单词组合而成

    类名和函数名用大写字母开头的单词组合而成。

    例如: class Node; // 类名 class LeafNode; // 类名 void Draw(void); // 函数名 void SetValue(int value); // 函数名

     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     static disp_count(void) //static成员函数
    13     {
    14         cout<<"The current instances count:";
    15         cout<<num<<endl;
    16     }
    17 };
    18 int ex::num=0;    //设置static数据成员的初值
    19 //main()函数测试ex类
    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     ex::disp_count();   //直接用类作用域符引用静态成员函数
    30 
    31     delete p;
    32     ex::disp_count();  //直接用类作用域符引用静态成员函数
    33     return 0;
    34 }
  • 相关阅读:
    删除指定字符
    Palindromes&nbsp;_easy&nbsp;version
    统计元音
    查找最大元素
    首字母变大写
    Intent加强
    GUI_键盘事件
    GUI_鼠标事件
    GUI_事件监听机制与ActionListener演示
    GUI概述与Frame演示
  • 原文地址:https://www.cnblogs.com/borter/p/9413426.html
Copyright © 2011-2022 走看看