3

I use visual c++. I have a template class and I want add overlapped operation for it I impelement it like below in header file

 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); }; 

in souce file

 template <class T> inline std::ostream & operator<< (std::ostream & os,const QuantityT<T> &quantity){ } 

but I get link error:

main.obj : error LNK2019: unresolved external symbol "class 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) referenced in function "public: virtual void __thiscall log::print(class std::basic_ostream

&)const " (?print@log@@UBEXAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@@Z

How I can fix it?

0

1 Answer 1

3

Try putting the source file's contents into the header file:

template <class T> inline std::ostream & operator<< (std::ostream & os,const QuantityT<T> &quantity){ } 

Check this question out for more information.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.