在本例中,有兩個函數的名稱為
foo
,且彼此超載。這可能導致非預期的行為。
template<class T> class MyClass { public: int foo(T type); int foo(int b); }; |
解決方案是如同下列範例的示範,撰寫特殊化函數,或是使用特殊化函數範本,來移除程式碼中任何語義不明確之處。
template<class T> class MyClass { public: int fncType(T type); int fncInt(int b); }; |