簡體   English   中英

在內聯函數中調用外部函數

[英]Calling outside functions in inline functions

說我有內聯函數:

// equality operator where left operand is a long
inline bool operator==(long num, BigInt const& val) {
    return compare(num, val) == 0;
}

在內聯函數所在的BigInt.h中定義了“比較”的位置。 如何使用比較,甚至可以使用比較?

BigInt.h

class BigInt {

public:

//code

int BigInt::compare(long num, BigInt const& other) const;

//code

};

// equality operator where left operand is a long
inline bool operator==(long num, BigInt const& val) {
    return compare(num, val) == 0;
}

compare是一個成員函數,您應該像這樣更改它的名稱

// equality operator where left operand is a long
inline bool operator==(long num, BigInt const& val) {
    return val.compare(num, val) == 0;
}

而且我仍然懷疑為什么compare是成員函數。 如果它與當前對象無關,則應該只是普通函數或靜態成員函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM