我使用视觉 C++。我有一个模板类,我想为它添加重叠操作我在头文件中像下面一样将它引入
template <class T> class QuantityT;
template <class T>
inline std::ostream & operator<< (std::ostream & os,const QuantityT<T> &quantity);
template <class T>
class QuantityT{
T quantity_;
template<class T> friend inline std::ostream & operator<< <T>(std::ostream & os,const QuantityT<T> &quantity);
};
在源文件中
template <class T>
inline std::ostream & operator<< (std::ostream & os,const QuantityT<T> &quantity){
}
但我收到链接错误:
main.obj:错误 LNK2019:未解析的外部符号“类 std::basic_ostream > & __cdecl operator<<(class std::basic_ostream > &,class QuantityT const &)”(??$?6K@@YAAAV?$basic_ostream@ DU?$char_traits@D@std@@@std@@AAV01@ABV?$QuantityT@K@@@Z) 在函数“public: virtual void __thiscall log::print(class std::basic_ostream
&)const " (?print@log@@UBEXAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@@Z
我该如何解决?