support bazel complie this project and format code.

This commit is contained in:
zhangxing
2023-03-30 00:15:11 +08:00
committed by light-city
parent 1f86192576
commit 3c8a3f259b
641 changed files with 10349 additions and 9523 deletions

View File

@@ -6,45 +6,46 @@
* @date 2019-08-06
*/
#include<iostream>
#include <iostream>
/**
* 默认访问控制符为public
*/
union UnionTest {
/**
* 可以含有构造函数、析构函数
*/
UnionTest() : i(10) {print(i);};
~UnionTest(){};
int i;
/**
* 可以含有构造函数、析构函数
*/
UnionTest() : i(10) { print(i); };
~UnionTest(){};
int i;
private:
void print(int i){std::cout<<i<<std::endl;};
void print(int i) { std::cout << i << std::endl; };
};
/**
* 全局匿名联合必须是静态的
* 全局匿名联合必须是静态的
*/
static union {
int i;
double d;
int i;
double d;
};
int main() {
UnionTest u;
UnionTest u;
union {
int i;
double d;
};
union {
int i;
double d;
};
std::cout << u.i << std::endl; // 输出 UnionTest 联合的 10
std::cout << u.i << std::endl; // 输出 UnionTest 联合的 10
::i = 20;
std::cout << ::i << std::endl; // 输出全局静态匿名联合的 20
/**
* 匿名union在定义所在作用域可直接访问union成员
*/
i = 30;
std::cout << i << std::endl; // 输出局部匿名联合的 30
::i = 20;
std::cout << ::i << std::endl; // 输出全局静态匿名联合的 20
/**
* 匿名union在定义所在作用域可直接访问union成员
*/
i = 30;
std::cout << i << std::endl; // 输出局部匿名联合的 30
return 0;
return 0;
}