2008年8月1日 星期五

[C++] class member function使用template注意事項

在寫一個class的時候,大多習慣把prototype放在.h檔,而定義則放在.cpp檔。

但是當你的member function有使用template時,如果把定義還是放在.cpp檔中,
在link的時候會出現unresolved external symbol,也就是找不到這個function。

所以必須要把這些有用template的function也放在.h檔裡面定義,這樣template就可以正確產生
不同type的function instances。

參考資料 :
http://bytes.com/forum/thread165359.html
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.7

沒有留言: