得之我幸 失之我命

when someone abandons you,it is him that gets loss because he lost someone who truly loves him but you just lost one who doesn’t love you.

类成员的访问权限

类的成员包括成员变量和成员函数

他们的访问权限由 pulibc、protected、private 决定,省略不写时(默认)等同于 private

  1. public:公开的,在派生类中可以访问,外部也可以通过对象访问
  2. protected:保护的,在派生类中可以访问,外部不能通过对象访问
  3. private:私人的,派生类和对象都不能访问

Read More...


类内的 static

静态成员变量

静态成员变量是一种特殊的成员变量,它以关键字 static 开头,这种成员变量的生存期大于 class 的对象(instance)。静态成员变量是每个 class 有一份,普通数据成员是每个对象各自拥有一份,因此静态成员变量也叫做类变量

1
2
3
4
5
6
class Test
{
public:
static int n;
};
int Test::n; // 不赋值,会被默认初始化

Read More...


匿名 namespace

1
2
3
4
namespce
{
char c;
}

这是啥?命名空间的名字呢?这个 c 要怎么在其他地方调用?

Read More...


Cpp11 auto

c++11 中的 auto 是一个占位符,编译器在编译期间自动推导出变量的类型,并适当地改变结果类型使其更符合初始化规则,因此 auto 定义的变量必须有初始值

1
2
int x;
auto y; // error

Read More...


搭建 Git 服务器

1
2
3
4
5
$ mkdir test.git  # 创建 Git 资源的存储目录 test.git
$ git init --bare test.git # 在 test.git 目录中初始化 Git 的基本配置信息
# 添加系统用户和用户组,如 test_git:test_git_grp
$ chown -R test_git:test_git_grp test.git # -R :递归,表示递归 test.git 中的所有文件归属到指定用户 test_git 上
$ git clone test_git@7.7.7.7:/home/test_git/test.git test

Read More...


1
2
3
4
5
6
7
8
9
10
11
12
struct child
{
char name[10];
};
struct child she = { "Jerry" };

int main()
{
static struct child she1 = { "Jerry1" };
struct child she2 = { "Jerry2" };
return 0;
}

Read More...


Cpp17 variant

std::variant

std::variant 是 C++17 中一个新加入标准函式库的 template 容器,使用时需要 #include

它的概念基本上是和 union 一样,是一个可以用来储存多种型别资料的容器;和 union 不同的是,std::variant 是 type-safe 的,再加上有许多函数可以搭配使用,所以在使用上应该算是相对安全

由于它是标准函式库的 template class,在使用时不需要另外去宣告一个新的类型

std::variant 在储存数据的时候,内部会有一个索引值来记录目前存储的是哪一个类型的数据

Read More...


the only present love demands is love