摘要:本篇文章,我们来了解一下C++中的几种构造函数,以及析构函数 #include <format> #include <iostream> #include <string> using std::format; using std::cout; using std::string; const st
阅读全文
摘要:C++中写class时,对私有变量通常使用set和get方法来进行访问,比较标准的例子 class A { int ia {}; int ib {}; int ic {}; public: A (int a, int b, int c) : ia(a), ib(b), ic(c) {} //构造函数
阅读全文
摘要:先来看看C++中call by value的function void func(int a) { ++a; } int main(){ int a {7}; func(a); cout << format("value is {}\n",a); //a 会输出7 } c++中call by ref
阅读全文
摘要:在C++中,比如我们可以把一个结构体struct的地址赋给一个指针pointer 然后使用这个指针去访问这个结构体中的元素时,可以使用pointer member D-reference operator: -> 用来access a member through a pointer #includ
阅读全文
摘要:在C++中,我们通常使用typedef来实现type alias. 比如: #include <cstdint> //C standard int typedef uint32_t points_t; //points_t is alias of uint32_t typedef uint64_t
阅读全文
摘要:union指的是C语言的共用体(联合体) a union is a container of overlapping object 共用体它表示几个变量共用同一个内存位置, 在不同的时间保存不同的数据类型和不同长度的变量 union中,里面全部的共用体成员共用同一个内存空间, 而且特别重要的一点是:
阅读全文
摘要:C++中为了和语言兼容,保留了C语言中的struct关键字,并且进行了适当扩充. C语言 => struct只是包含成员变量,但不包括成员函数 C++中 => struct和class非常类似,既可以包括成员变量,又可以包括成员函数 也就是说C++中,struct和class基本上是可以通用的,只有
阅读全文