- 论坛徽章:
- 2
|
請教 template樣版
- //#include "a.h"
- #include <iostream>;
- using namespace std;
- struct teacher
- {
- };
- class student
- {
- public:
- int a;
- char* str;
- template<class Y>;
- void function_Call(Y& struct1, teacher& teach,int);
- };
- template<class Y>;//Y為不同的類
- void student::function_Call(Y& struct1, teacher& teach,int flag)
- {
- cout << "in func_Call"<<endl;
- }
- main()
- {
- student stu;
- teacher struct1;
- teacher teach;
- int flag;
- stu.function_Call(struct1,teach,flag);
- }
复制代码
或者
- //a.h
- #include <iostream>;
- using namespace std;
- struct teacher
- {
- };
- class student
- {
- public:
- int a;
- char* str;
- template<class Y>;
- void function_Call(Y& struct1, teacher& teach,int);
- };
- template<class Y>;//Y為不同的類
- void student::function_Call(Y& struct1, teacher& teach,int flag)
- {
- cout << "in func_Call"<<endl;
- }
复制代码
- //a.cpp
- #include "a.h"
- main()
- {
- student stu;
- teacher struct1;
- teacher teach;
- int flag;
- stu.function_Call(struct1,teach,flag);
- }
复制代码 |
|