Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
45 lines (37 loc) · 951 Bytes

File metadata and controls

45 lines (37 loc) · 951 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
// Created by light on 19-11-3.
//
#include <iostream>
#include <vector>
using namespace std;
// 第一种使用
// type alias
// 等价于typedef void(*func)(int, int);
using fun=void (*)(int, int);
void example(int, int) {}
// 第二种使用
template<typename T>
struct Container {
using value_type=T; // 等价于typedef T value_type;
};
template<typename Cn>
void func2(const Cn &cn) {
typename Cn::value_type n;
}
// 第三种使用
// alias template
template<typename CharT>
using string=basic_string<CharT, char_traits<CharT>>;
// 等价于 typedef basic_string<char> string;
// 综上:type alias等价于typedef,没有什么不同
// using 的所有用法拓展如下:
// 1.using-directives
// using namespace std; or using std::cout;
// 2. using-declaration
// protected:
// using _Base::_M_alloc;
// 3.c++2.0特性 type alias and alias template
int main() {
fun fn = example; // 函数指针
return 0;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.