forked from mcpp-community/d2mcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00-auto-and-decltype-0.cpp
More file actions
46 lines (38 loc) · 1.07 KB
/
00-auto-and-decltype-0.cpp
File metadata and controls
46 lines (38 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// d2mcpp: https://github.com/mcpp-community/d2mcpp
// license: Apache-2.0
// file: dslings/cpp11/00-auto-and-decltype-0.cpp
//
// Exercise/练习: cpp11 | 00 - auto and decltype | 自动类型推导
//
// Tips/提示: 使用 auto 和 decltype 修复代码中的错误
//
// Docs/文档:
// - https://en.cppreference.com/w/cpp/language/auto
// - https://en.cppreference.com/w/cpp/language/decltype
// - https://github.com/mcpp-community/d2mcpp/blob/main/book/src/cpp11/00-auto-and-decltype.md
//
// 练习交流讨论: http://forum.d2learn.org/post/357
//
// Auto-Checker/自动检测命令:
//
// d2x checker auto-and-decltype
//
#include <d2x/cpp/common.hpp>
int main() {
// 0. 声明定义
int a = 1;
auto a1 = a; // a1 的类型是 int
int b = 2;
D2X_YOUR_ANSWER b1 = b;
decltype(b) b2 = b; // b2 的类型是 int
D2X_YOUR_ANSWER a2 = a;
char c = 'c';
D2X_YOUR_ANSWER c1 = c;
D2X_YOUR_ANSWER c2 = c;
d2x_assert_eq(a, a1);
d2x_assert_eq(a1, a2);
d2x_assert_eq(b, b1);
d2x_assert_eq(b1, b2);
D2X_WAIT
return 0;
}