//类模板中成员函数创建时机

//类模板中成员函数创建时机
//类模板中成员函数和普通类中成员函数创建时机是有区别的
//普通类中的成员函数一开始就可以创建
//类模板中的成员函数在调用时才创建

#include
using namespace std;

class Person1
{
public:
void shouPerson1()
{
cout << “Person1 show” << endl;
}
};

class Person2
{
public:
void shouPerson2()
{
cout << “Person2 show” << endl;
}
};
template
class MyClass
{
public:
T obj;
//类模板中的成员函数
void func1()
{
obj.shouPerson1();

}
void func2()
{
	obj.showPerson2();
}

};

void test1()
{
MyClassm;
m.func1();
//m.func2();

}

int main()
{
test1();
system(“pause”);
return 0;
}
//总结:类模板中的成员函数并不是一开始就创建的,在调用时才去创建的

猜你喜欢

转载自blog.csdn.net/ADADQDQQ/article/details/108433625