如果我显式实例化具有默认析构函数,默认move构造函数等的模板类,并且从不在该转换单元中使用该类型,则它不包括编译器生成的成员函数。
例如,如果模板类array2d
具有编译器生成的成员函数,例如:
array2d(array2d const &b) = default;
array2d(array2d &&b) noexcept = default;
~array2d() = default;
array2d &operator=(array2d const &) = default;
array2d &operator=(array2d &&) noexcept = default;
如果我像这样显式实例化它:
#include "array2d.hh"
template class array2d<float>;
并将其编译为array.cc.o
,我得到以下符号:
0000000000000000 W void swap<float>(array2d<float>&, array2d<float>&)
0000000000000000 W array2d<float>::swap(array2d<float>&)
0000000000000000 W array2d<float>::array2d(long, long)
0000000000000000 W array2d<float>::array2d()
0000000000000000 W array2d<float>::array2d(long, long)
0000000000000000 W array2d<float>::array2d()
0000000000000000 n array2d<float>::array2d(long, long)
0000000000000000 n array2d<float>::array2d()
0000000000000000 W array2d<float>::operator()(long, long)
0000000000000000 W array2d<float>::operator[](long)
0000000000000000 W array2d<float>::rows() const
0000000000000000 W array2d<float>::empty() const
0000000000000000 W array2d<float>::columns() const
0000000000000000 W array2d<float>::operator()(long, long) const
0000000000000000 W array2d<float>::operator[](long) const
编译器生成的成员函数的符号均不存在。
为什么显式模板类实例化不创建这些符号?