まあ、私は明示的なテンプレートのインスタンス化によって非常に混乱していると思います ~>_<~
- 明示的なインスタンス化宣言は、暗黙的なインスタンス化定義を悪用できますか?
- 明示的および暗黙的なインスタンス化定義がプログラムに存在する場合はどうなりますか? それらは最終的に1つに崩壊しますか?
- 明示的なインスタンス化宣言は、暗黙的なインスタンス化の定義の後に配置すると効果がありますか?
また、次のコードも参照してください。
#include <iostream>
#include <vector>
std::vector<int> a; // Implicit instantiation definition.
// Explicit instantiation declaration.
extern template class std::vector<int>;
int main() {
std::cout << std::vector<int>().size(); // So what?
}
リンクエラーの原因となります
/tmp/ccQld7ol.o: In function `_GLOBAL__sub_I_a':
main.cpp:(.text.startup+0x6e): undefined reference to `std::vector<int, std::allocator<int> >::~vector()'
collect2: error: ld returned 1 exit status
GCC 5.2 を使用しますが、clang 3.6 で正常にビルドされます。基準で正しいのはどれか。
上記のすべての質問に対する答えを論理的に推測して説明できるように、明示的なテンプレートのインスタンス化を理解するための洞察に満ちた方法があることを願っています。