mirror of
https://github.com/changkun/modern-cpp-tutorial.git
synced 2025-12-17 04:34:40 +03:00
revision #2: 检阅部分模板相关内容
This commit is contained in:
32
code/2/2.13.alias.template.cpp
Normal file
32
code/2/2.13.alias.template.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// 2.13.alias.template.cpp
|
||||
// chapter 2 language usability
|
||||
// modern cpp tutorial
|
||||
//
|
||||
// created by changkun at changkun.de
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
template<typename T, typename U>
|
||||
class MagicType {
|
||||
public:
|
||||
T dark;
|
||||
U magic;
|
||||
};
|
||||
|
||||
// illegal
|
||||
// template<typename T>
|
||||
// typedef MagicType<std::vector<T>, std::string> FakeDarkMagic;
|
||||
|
||||
typedef int (*process)(void *);
|
||||
using NewProcess = int(*)(void *);
|
||||
template<typename T>
|
||||
using TrueDarkMagic = MagicType<std::vector<T>, std::string>;
|
||||
|
||||
int main() {
|
||||
// FakeDarkMagic<bool> me;
|
||||
TrueDarkMagic<bool> you;
|
||||
}
|
||||
Reference in New Issue
Block a user