main.cpp
class UrlTable {};
//不管是静态的还是非静态的,类数据成员前面加下划线
struct Pool {};
class Tableinfo
{
private:
std::string _tableName;
static Pool* _pool;//下划线
};
struct UrlTables {};
struct UrlTableProperties
{
std::string name;
int numEntries;
static Pool* pool;//无下划
};
using PropertiesMap = std::map<std::string, UrlTables*>;
enum class UrlTableErrors {};//大驼峰(首字母大写)
enum CoLorSet { Red, Blue, White, Black }; //小驼峰(eg:redBlue) 定义枚举类型
enum Week { Sun, Mon, Tue, Wed, Thu, Fri, Sat }; // 定义枚举类型week
bool addTableEntry();//小驼峰
const int MAX_NUM1 = 100;
constexpr int MAX_NUM2 = 200;
int g_Count = 0;//尽量少用,有构造函数的类不能作为全局变量
//using namespace std;
namespace zhang{}//张公子的命名空间
//顶级命名空间的名称应当是项目名或者是该命名空间中的代码所属的团队的名字。【建议】
//命名空间中的代码, 应当存放于和命名空间的名字匹配的文件夹或其子文件夹中。【建议】
//命名空间结尾的}后面应该加注释。
table-- > tbl
argument-- > arg
buffer-- > buf
clock-- > clk
command-- > cmd
config-- > cfg
device-- > dev
error-- > err
message-- > msg
maximum-- > max
minimum-- > min
parameter-- > para
previous-- > prev
register -- > reg
statistic-- > stat
initialize-- > init
synchronize-- > sync
communication-- > comm
internationalization-- >i18n
顺序:
#include "ncpcore.h" // 优先位置
#include "ncp/ncpplugin.h" // 本项目头文件
#include // 系统头文件
#include
#include // 库头文件
以前练习最常用:using namespace std;成员函数后面加const,不仅语义更清晰,而且函数可以被常量对象 const T& 调用。
函数式宏:#define sqr(x) ((x) * (x))详见:
详见:
std::vector<int> vec;
for (int i = 1; i < 5; ++i)
{
vec.push_back(i);
}
for (const auto& p : vec)
{
std::cout << p;
}
标志变量是坏代码的表现:bool hasDog = false //坏代码
当一个类实现了以下五项之一时,也应该实现其他四项: