【发布时间】:2018-06-14 03:37:15
【问题描述】:
是否可以有两个函数名称不同但功能相同的函数共享函数体?我们该怎么做呢?
template<typename _T>
class array {
public:
_T operator+(_T concatinate_operand); // concatinate to the array
_T append(_T concatinate_operand);
};
【问题讨论】:
-
你可以只打一个电话。
-
但是您需要不同的
+运算符重载语义。 IE。类似array& operator+(const array& rhs) { append(rhs.data_,rsh.length_); return *this; }; -
完全和完全无关:任何时候在大写字母前加下划线时都表现出一点恐惧。为什么,请阅读What are the rules about using an underscore in a C++ identifier?