【发布时间】:2012-06-28 20:28:17
【问题描述】:
我想知道,当我创建具有指定模板类型参数的类模板实例时。
1) 为什么未调用的函数没有被实例化? .
2) 在我尝试使用它之前,它们不会被编译吗?
3) 这种行为背后的逻辑是什么?
示例
template <class T>
class cat{
public:
T a;
void show(){
cout << a[0];
}
void hello(){
cout << "hello() get called \n";
}
};
int main(){
cat<int> ob1; // I know that show() did not get instatiated, otherwise I will get an error since a is an int
ob1.hello();
}
【问题讨论】: