前言
在模板类<>传递参数的一种实现。记不住,以此记录。
- // dome.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
- //
- #define _CRT_SECURE_NO_WARNINGS
- #include
- //#include "tools.h"
- #include
- using namespace std;
- #include
-
- template <class T>
- class A
- {
- public:
- T name;
-
- };
- template <class T>
- class AA
- {
- public:
- T name;
-
- };
- template <template<class> class TT, class T, class T1> //声明形式
- class B
- {
- public:
- TT
a; - T1 age;
- };
-
- int main()
- {
- //传递的是对象A或者AA
- b.a.name = "222";
- cout << b.a.name << endl;
-
- B
int> bb; - bb.a.name = "222";
- cout << b.a.name << endl;
- return 0;
- }
-
结果:
