[英]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.