简体   繁体   中英

Calling outside functions in inline functions

Say I have the inline function:

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

where 'compare' is defined in BigInt.h where the inline function is. How can I use compare or can I even use it?

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 is a member function, you should change call it like

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

And I'm still doubt why compare is a member function. If it has nothing to do with the current object it should be just a normal function or static member function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM