示例

在此示例中,我们有两个名为 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);
};