zoukankan      html  css  js  c++  java
  • C++ 命名规范小结

    1. #defines and const

    test.h

    #ifndef TEST_H
    #define TEST_H
    #endif
    
    #define FALSE 0
    #define TRUE (!FALSE)
    
    #define MAX_NO_OF_STUDENT 100
    const int MAX_NO_OF_STUDENT = 100;
    

    2.Function(函数)

    int m_iGetValues();
    m_ : a member of a class
    i  : returns a int
    
    long m_lGetValues();
    m_ : a member of a class
    l  : returns a long 
    
    int * m_piGetValus();
    m_ : a member of a class
    p  : returns pointer
    i  : a int pointer
    
    void * m_pvDoSomething();
    m_ : a member of a class
    p  : returns pointer
    v  : a void pointer
    
    unsigned char ucGetValues();
    uc : This returns unsigned char
    
    bool bIsRunning();
    b : returns a bool 
    
    void m_vSetValues(int iNum);
    m_ : a member of a class
    v  : there is no return value
    

    If the function is not a member of a class, then 'm_' prefix is not used.Example:

    //global function
    int g_iGetValues();
    g_ : a global functions 
    i  : returns a int
    

    3.Variables(变量)

    //在 int变量 的最前面加上一个小写的i,之后每个单词的第一个字母大写
    int iNum;
    int iNoOfVariables;
    
    //在数组的最前面加上a(array),然后紧接着一个数组类型的字母。
    char acFileName[128];  ac代表一个字符类型的数组
    int aiNum[128];  ai代表这是一个int类型的数组
    char *apcFileName[128];  这是一个数组,数组中保存着128个char类型的指针
    char (*pacFileName)[128];  这是一个指针,
    
    //在变量的最前面加上 m_, 代表这是一个类或者是一个结构体中的成员变量。
    typedef struct _SNode {
        char * m_pcName;  //m_:结构体成员; pc:指向char类型的指针
    	struct _SNode * m_pstNext;  //m_结构体成员; pst:指向struct类型的指针
    }SNode;
    

    4.总结

    具体代码参考链接:http://mdgsf.xyz/?p=31

    My Github Blog: mdgsf.github.io
  • 相关阅读:
    mysql-主主配置
    PHP安装-centos7
    mysql-M-S-S模型 中继器 级联
    安装mysql数据库-centos7
    正则表达式
    DJango安装-windows
    flask安装
    python安装centos7
    Linux——C库
    文件I/O
  • 原文地址:https://www.cnblogs.com/mdgsf/p/4859658.html
Copyright © 2011-2022 走看看