#include<iostream>
#include <new>
#include<stdio.h>
using namespace std;
/**
* url:http://www.cplusplus.com/doc/tutorial/other_data_types/
*/
/**
* in which all its member elements occupy the same physical space in memory.
* The size of this type is the one of the largest member element
*/
union mytypes_t
{
char c;
int i;
float f;
} mytypes;
/**
* 枚举类,注意不是枚举类型,语法如下
*/
//They are declared with enum class (or enum struct) instead of just enum:
enum class Colors
: long
{
black, blue, green
};
enum Color2
{
black2, blue2, green2, white
};
enum class EyeColor
: char
{ blue, green, brown
};
//大神解说 https://zhuanlan.zhihu.com/p/21722362
//enum Color
//{
// //编译出错,重新定义white
// black, white, red
//equals this
//#define black 0
//#define white 1
//#define red 2
//};
//that is ok
enum class Color
{
black, white, red
};
// auto white = false; // error
template<class T> void f(T t)
{
using tt = T;
tt t2;
t2 = t;
typedef T ttt;
ttt t3 = t;
}
int main()
{
/**
* 类型别名
* 继承自c
* typedef existing_type new_type_name;
* c++
* using new_type_name=existing_type
*/
typedef char C_1;
C_1 c = 'A';
using C_2 = char;
C_2 cc = 'B';
f(10);
Colors mycolor;
mycolor = Colors::black;
if(mycolor == Colors::black)
{
mycolor = Colors::blue;
}
//只有一个字节长度噢
cout << sizeof(EyeColor) << endl;
cout << sizeof(Colors) << endl;
cout << sizeof(Color2) << endl;
return 0;
}