我剛剛開始閱讀關於C++中的模板類,並且遇到了一些我不知道的語法。 類方法的原型爲:C++模板類中的'const'方法
template <class Type> class Range {
....
bool Below (const Type& value) const;
....
}
,並定義爲:
template <class Type> bool Range<Type>::Below(const Type& Value) const {
if (Value < Lo) return true;
return false;
}
誰能幫助我理解了「常量」標誌意義的方法輸入已上市之後? 我明白那裏使用時,輸入前,但不是之後。 乾杯, 傑克
與模板無關。在構建[testcase](http://sscce.org)時,你會發現這只是成員函數的一個特性。 –
const有時會令人困惑,除非你知道你爲什麼使用它。除了這裏的好答案,請閱讀防禦性編程,[const-correctness](http://stackoverflow.com/questions/136880/sell-me-on-const-correctness) – mungflesh