在VC6下以下操作符会有问题
friend bool operator == (const PRICE& lhs, const PRICE& rhs);
friend bool operator != (const PRICE& lhs, const PRICE& rhs) { return !(lhs == rhs); };
error C2593: 'operator >' is ambiguous
正确的用法是如下
bool operator == (const PRICE& rhs);
bool operator != (const PRICE& rhs) { return !(*this == rhs); };
实际使用是这样的 price pc1, pc2;
pc1 == pc2
同样的, pc1- pc2 也是一个函数看着象确东西似的,其实就这样就可以.
本文详细介绍了在VC6环境下解决运算符冲突的方法,并提供了正确的比较函数实现方式,帮助开发者避免常见错误。
3万+

被折叠的 条评论
为什么被折叠?



