在编译时,类模板会发生什么

At compilation what happen with class template

本文关键字:什么 编译      更新时间:2023-10-16

当类模板实例化时会发生什么。 即我hv一个类模板,我已经为int创建了类,为float创建了类,那么在编译时会发生什么(编译器将为int和float创建2个单独的类(或不? 例如:

template <typename T>
class A
{
public:
void foo(T t)
{
//...
};
};
int main()
{
A<int> a; 
A<float> b;
}

是的,编译器将即时创建两个新类 - 一个用于 int,一个用于浮点数。