foreachauto 自动类型推断lambda 匿名函数override 关键字nullptr 代替原来的 NULLvoid a(int x); 和 void a(char *x) 时,若使用 a(NULL) 则会调用前者,这与通常的理解不同,而使用 a(nullptr) 则会明确的调用后者get<>() 取出其中的一个值,或者使用 tie() 装包或解包{} 进行初始化,而 class 则需要所有成员变量都是 public 的时候才可以使用=0| 转换 | 特点 |
|---|---|
| static_cast | 普通的转换,与普通的 C 语言的强制类型转换相同,在编译期间进行转换,所以会检查转换是否合法 |
| const_cast | 去除 const 属性,但是不能去除其本身的 const 属性 |
| reinterpret_cast | 无条件强制转换 |
| dynamic_cast | 将基类转换为派生类 |
| 描述 | |
|---|---|
| private | 私有的,仅此类可以访问此属性 |
| protect | 保护的,仅此类已经此类的派生类可以访问此属性 |
| public | 公有的,任意对象和方法可以访问此属性 |
main () {
printf("xxx");
fork();
}
xxxxxxxxxxxxsizeof 可以求得在 32 位操作系统下,指针的大小为 $4$ 个字节,而引用则为原对象的大小auto_ptr(已弃用)new 的对象只能由一个 auto_ptr 来指向,进行赋值操作会使得原来的指针丢失指向的对象unique_ptrauto_ptr 相同,但是进行赋值操作时,会直接报错,而 auto_ptr 不会shared_ptrweak_ptrshared_ptr 对象,此指针不会影响 shared_ptr 的析构行为,通常用来避免相互指向问题new/malloc 函数时动态管理分配的内存,同时需要用 delete/free 来手动释放mmap 函数进行的文件映射类名.方法名 和 对象名.方法名,而实例方法只能用后者hash 函数的实现hash 函数返回值为此变量的值,不做修改string,hash 函数对每四个字节(64位操作系统下)进行位运算最终得到结果,实际的内部过程使用了两个特殊的固定值,下面是 C++ 的字符串 hash 函数的实际内部实现(C++11)
```cpp
inline std::size_t unaligned_load(const char *p) {
std::size_t result;
__builtin_memcpy(&result, p, sizeof(result));
return result;
}size_t _Hash_bytes(const void ptr, size_t len, size_t seed = 0xc70f6907UL) { const size_t m = 0x5bd1e995; size_t hash = seed ^len; const char buf = static_cast<const char *>(ptr);
// Mix 4 bytes at a time into the hash.
while (len >= 4) {
size_t k = unaligned_load(buf);
k *= m;
k ^= k >> 24;
k *= m;
hash *= m;
hash ^= k;
buf += 4;
len -= 4;
}
// Handle the last few bytes of the input array.
switch (len) {
case 3:
hash ^= static_cast<unsigned char>(buf[2]) << 16;
[[gnu::fallthrough]];
case 2:
hash ^= static_cast<unsigned char>(buf[1]) << 8;
[[gnu::fallthrough]];
case 1:
hash ^= static_cast<unsigned char>(buf[0]);
hash *= m;
};
// Do a few final mixes of the hash.
hash ^= hash >> 13;
hash *= m;
hash ^= hash >> 15;
return hash;
} ```