#include<iostream>using namespace std;#include<string.h>//类模板中成员函数的创建时机//类模板中成员函数在调用时才去创建class person1 {public:void show1() {cout << "person1 show1" << endl;}};class person2 {public:void show2() {cout << "person2 show2" << endl;}};template<class T>class myclass {public:T obj;void func1() {obj.show1();}void func2() {obj.show2();}};//类模板中成员函数在调用时才去创建void test01() {myclass<person1>m;m.func1();//m.func2();//不可调用}int main() {test01();return 0;}
类模板中成员函数在调用时才去创建
