1、auto自动推断变量
auto根据变量初始化来推断变量类型。示例如下:
auto array = new int[8];
2、decltype推断变量类型
与auto不同的是,decltype是根据表达式来推断变量类型。语法格式如下:
decltype(expression) var;
表达式包括:变量、运算、函数等,示例如下:
long add() {
return 0;
}
void hello() {
int a = 2;
decltype(a) b; // b为int类型
decltype(add()) c; // c为long类型
}
3、bool布尔变量
bool关键字表示布尔变量,只有true或false两种变量值。
4、throw/try/catch异常处理
使用关键字throw抛出异常,使用try/catch来捕获异常。示例代码如下:
try {
std::string msg("This is a test exception");
throw msg;
} catch (const std::string &e) {
&nbs
订阅专栏 解锁全文
1万+

被折叠的 条评论
为什么被折叠?



