类模板中成员函数和普通函数创建时机是有区别的:
#include<iostream>
using namespace std;
class Demo1{
public:
static void show_demo1(){
cout<<"This is Demo1."<<endl;
}
};
class Demo2{
public:
static void show_demo2(){
cout<<"This is Demo2."<<endl;
}
};
template<class T>
class Test{
public:
T ob;
void func1(){
ob.show_demo1();
}
void func2(){
ob.show_demo2();
}
};
void test(){
Test<Demo1> t{};
t.func1();
// t.func2(); 调用时才创建的。
Test<Demo2> s{};
s.func2();
}
int main(){
test();
return 0;
}