由于我无法解释这一点,我将立即从一个小例子开始:
template <class T> void Print(const T& t){t.print1();}
template <class T> void Print(const T& t){t.print2();}
Run Code Online (Sandbox Code Playgroud)
这不编译:
error C2995: 'void Print(const T &)' : function template has already been defined
那么,我怎样才能创建一个模板函数,T只要该类型具有print1成员函数或print2成员函数(没有多态性),它就采用任何类型?
| 归档时间: |
|
| 查看次数: |
296 次 |
| 最近记录: |