gpt4 book ai didi

c++ - 警告和 SunStudio C++ 编译器

转载 作者:行者123 更新时间:2023-11-27 23:35:35 25 4
gpt4 key购买 nike

我说服我的团队再次打开编译器警告。一些如何禁用所有警告(-w)(不要问......)。其中大多数是显而易见的,但其中一个真的很烦人。我从我在很多地方使用的日期和时间类(class)中得到它。故事真的很简单。 Time 是 Date 的子类,它们都定义了自己的运算符。这有什么问题?这是我收到的警告:

Warning: ACTime::operator- hides the function ACDate::operator-(const ACDate&) const.

也许有人可以给我链接描述每个 SunStudio C++ 编译器警告的含义的文档?我找不到这个...谢谢!

最佳答案

我以前在 SunStudio 编译器中看到过这种情况。基本上,您有这样的结构:

class ACDate
{
public:
ACDate &operator-(const ACDate &);
};

class ACTime : public ACDate
{
public:
ACTime &operator-(const ACTime &);
};

由于 C++ 作用域规则,ACTime::operator- 在 ACTime 对象的上下文中隐藏了 ACDate::operator-。这是很正常的,但 SunStudio 编译器会警告此问题,因为它可能是缺少“虚拟”限定符的标志。

针对这种情况的一种解决方法是在 ACTime 的类声明中显式“使用 ACDate::operator-”,但这可能不是您想要的。

对于您的情况,另一种可能更好的解决方法是使运算符(operator)成为免费 friend 功能,但这可能会导致其他有趣的问题。

关于c++ - 警告和 SunStudio C++ 编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/466827/

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