gpt4 book ai didi

c++ - 在内联函数中调用外部函数

转载 作者:行者123 更新时间:2023-11-30 03:47:29 24 4
gpt4 key购买 nike

假设我有内联函数:

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

其中 'compare' 在内联函数所在的 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 是一个成员函数。如果它与当前对象无关,它应该只是一个普通函数或静态成员函数。

关于c++ - 在内联函数中调用外部函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33665724/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com