使用C++ typeid关键字时,传入非泛型模板类通过编译,传入不含<<重载运算符的模板类通过编译,只有传入含有<<重载的模板类有问题,显示:
//main.cpp
auto a = typeid(MSTL::array<int, 3>).name(); // 删除后即可通过编译
//array.h
template <typename Tp, size_t Np>
friend std::ostream& operator <<(std::ostream& _out, const MSTL::array<Tp, Np>& _arr) { // 删除后也可通过编译
_arr._show_data_only(_out);
return _out;
}
inline void _show_data_only(std::ostream& _out) const { // 附_show_data_only实现,本人复现多次认为报错与他无关
auto _band = this->_size - 1;
_out << '[' << std::flush;
for (size_t i = 0; i < this->_size; i++) {
_out << this->_data[i] << std::flush;
if (i != _band) _out << ", " << std::flush;
}
_out << ']' << std::flush;
}
本人不知<<已被定义问题从何而来,求帮助!