我想知道当我通过指定模板类型参数创建类模板的实例时.
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();
}
Run Code Online (Sandbox Code Playgroud)