1 /*test for struct binding*/
2
3 #include <string>
4 #include <iostream>
5 using namespace std;
6 //命名空间 可以缩写为A::B
7 namespace NA::NB
8 {
9 class Data
10 {
11 public:
12 float a;
13 int b;
14 string data;
15 };
16 Data ff()
17 {
18 //保证声明时 属性是可访问的
19 return { 23.0f,41,"abcdef" };
20 }
21 }
22
23 int main()
24 {
25 {
26 //这里可以使A,B,C 可以用来捕获
27 //作用于当前范围
28 auto[A, B, C] = NA::NB::ff();
29 //[[std:cout]]
30 cout << A << endl;
31 cout << B << endl;
32 cout << C << endl;
33 }
34 using namespace NA::NB;
35 //无法使用auto
36 Data obj = { 23.0f,41,"abcdef" };
37 //编译期断言 ,如果不满足条件则会error
38 //static_assert(false,"这个地方编译不通过");
39 static_assert(true, "这个地方编译不通过");
40 return 0;
41 }