テンプレートクラスのメンバー関数をいつ呼び出すか知りたいです。定義はどこで生成されますか? 例えば:
template <class T>
class A{
public:
A(){cout << "A<T>::A() " << endl;}
void f(){cout << "A<T>::f() " << endl;}
};
int main(){
A<int> ob; // Time t1
ob.f(); // Time t2
}
ポイント1とポイント2A<int>
でテンプレートクラスがどのように見えるか知りたい
ケース 1 :
時間 t1:
class A<int>{
public:
A(){cout << "A<T>::A()" << endl;} // A() body is defined inline
void f(); // becasue I didn't call A<int>::f yet so there is just a declaration
};
時間 t1
class A<int>{
public:
A(){cout << "A<T>::A()" << endl;} // A() body is defined inline
void f(){cout << "A<T>::f()" << endl;} // f() is defined inline
};
ケース 1 :
時間 t1
class A<int>{
public:
A();
void f();
};
A<int>::A(){cout << "A<T>::A()" << endl;} // this is not inline
時刻 t2
class A<int>{
public:
A();
void f();
};
A<int>::A(){cout << "A<T>::A()" << endl;} // this is not inline
void A<int>::f(){cout << "A<T>::f() " << endl;}// this is not inline
では、2 つのケースのどちらが正しいのでしょうか?