C++主要的新语言特性
C++11 新加入的关键字
- alignas
- alignof decltype
- auto
- static_assert
- using
- noexcept
- export(弃用, 不过未来可能留作他用)
- nullptr
- constexpr
- thread_local
兼容的宏定义
- “func” 预定义标识符:
其基本功能就是返回所在函数的名字,在C++11 C++11 中, 标准甚至允许其使用在类或者结构体中。如下代码清单:
#include <iostream>
using namespace std;
struct TestStruct {
TestStruct () : name(__func__) {}
const char *name;
};
int main() {
TestStruct ts;
cout << ts.name << endl; // TestStruct
}
// 编译选项 :g++ -std=c++11 2-1-3.cpp
不过将func标识符作为函数参数的默认值是不允许的。
– _Pragma 操作符
-
变长参数的宏定义以及 __VA_ARGS__
-
宽窄字符串的连接
-
long long型
long long 整型有两种 : long long 和 unsigned long long。 在 C++11 中, 标准要求 long long 整型可以在不同平台上有不同的长度, 但至少有 64 位。 我们在写常数字面量时, 可以 使用 LL 后缀(或是 ll) 标识一个 long long 类型的字面量, 而 ULL(或 ull、 Ull、 uLL) 表示 一个 unsigned long long 类型的字面量,同其他的整型一样。要了解平台上的long long的大小,就是查看或<limits.h>中的宏,代码清单如下
#include <climits>
#include <cstdio>
using namespace std;
int main() {
long long ll_min = LLONG_MIN;
long long ll_max = LLONG_MAX;
unsigned long long ull_max = ULLONG_MAX;
printf("min of long long: %lld\n", ll_min); // min of long long:
-9223372036854775808
printf("max of long long: %lld\n", ll_max); // max of long long:
9223372036854775807
printf("max of unsigned long long: %llu\n", ull_max); // max of unsigned long long: 18446744073709551615
} // 编译选项 :g++ -std=c++11 2-2-1.cpp