C++(31)-Google编码规范-示例

   看了google编码规范,做了一些整理与示例。

   文件名、变量名:          小写  可拼接 “_”“-”。
   类名、函数名、常量:   首字母大写。
   宏、枚举:                     全大写。
   myclassfile.h

//1.文件名  小写  有_线或者-  与类名对应
myclassfile.cpp
my_class_file.cpp
    
myclassfile.h
      
//2.类名  单词以大写字母开头
class MyClassFile:public BasicClass //
{
    //1 常量 以k开头全单词
   const int kDaysInAWeek=7;
   //2 构造函数 析构函数
   public: 
    MyClassFile();
    explicit MyClassFile(int var);
    ~MyClassFile();
   //3.成员函数 单词以大写字母开头
    void Foo();
    void Foo(const string &text);
    void Foo(const string &in,string  *out);//输入引用加上const,输出
    int ErrorNum() const{return error_nums_;}
    //4 成员变量:全小写,_下划线结尾
   private:     
    string  table_name_str_;   
    string  errorname_;
    int  error_nums_;
    list alarm_lists_;           // 类型放在词尾
    CTime start_time_;        
    unordered_map    table_name_map_;         
};

 myclassfile.cpp

myfilename.cpp
//1.宏 全大写     有_线
#define PI_ROUNDE  3.0
//2.包含头文件  C文件  C++文件 其它
#include "foo/myclassfile.h"
//c
#include <sys/types.h>
#include <unistd.h>
//c++
#include <hash_map>
#include <vector>
 //其它
#include <base/basicclass.h>

MyClassFile::MyClassFile(){
    
}
//3.函数
 void MyClassFile::Foo()
 {
     //常量声明与初始化
     const char KFrogSays[]="helloworld";
     //4. 变量声明和初始化在一行 
     //强制类型转换 内建变量static_cast<>
     int a = 8;
     int b = 3;
     double result = static_cast<double>(a) / static_cast<double>(b);
     //dynamic_cast 子类->父类
       BasicClass *pbasicclass;
       MyClassFile *pmyclassfile;
       pmyclassfile=dynamic_cast(pbasicclass);
     //5.条件语句
     if(){
         
     }else{
         
     }
     
     switch(i){
         case 1:
         ...
         case 2:break;
     }
 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值