17 Star 242 Fork 115

Yj / CPlusPlusThings

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
type_alias.cpp 951 Bytes
一键复制 编辑 原始数据 按行查看 历史
light-city 提交于 2020-03-03 09:34 . update
//
// 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;
}
C++
1
https://gitee.com/yj404/CPlusPlusThings.git
git@gitee.com:yj404/CPlusPlusThings.git
yj404
CPlusPlusThings
CPlusPlusThings
master

搜索帮助