我創建了功能replaceElement
。我不確定old
參數應該是第一還是第二。這種情況下參數順序的常用方式是什麼?哪個參數應該是「老」還是「新」?
void replaceElement(Element *old, Element *n);
或
void replaceElement(Element *n, Element *old);
我創建了功能replaceElement
。我不確定old
參數應該是第一還是第二。這種情況下參數順序的常用方式是什麼?哪個參數應該是「老」還是「新」?
void replaceElement(Element *old, Element *n);
或
void replaceElement(Element *n, Element *old);
我會選擇void replaceElement(Element *old, Element *n);
這聽起來對我來說更好,也可以稍後設置默認參數。而你的情況的默認值是new
。
而且這std::replace
是如何形成的:
template< class ForwardIterator, class T >
void replace(ForwardIterator first, ForwardIterator last,
const T& old_value, const T& new_value);
+1和接受因爲提供的例子 – kravemir 2012-07-21 09:54:11
在C++中,它通常是第一個目的地,然後源
,所以我不得不說目的地=老源=新
先老,那麼新。您將該功能命名爲replaceElement
。所以,你看:
void replaceElement(Element* old, Element* n);
爲:
與
n
更換濾芯
old
,我認爲它簡單,因爲你會說出來。 「用新花替換舊花。」聽起來是對的。 – Dementic 2012-07-21 09:40:18在ELement類/結構本身中提供複製/移動構造函數,賦值運算符甚至自定義函數有什麼問題?然後你可以寫'n = old'或'n.replaceby(old)'或甚至'Element new {old}';所有這些語言結構都是有原因的,這不是應該在非成員函數中使用的東西(除非它是一個賦值運算符)。 – KillianDS 2012-07-21 09:41:57
可能會更好:「當前」和「新」? Order「current」是第一個更好(來自標準c-library範例「第一個目標參數」) – 2012-07-21 09:47:03