警告和 SunStudio C++ 编译器

发布于 2024-07-12 09:56:18 字数 358 浏览 7 评论 0原文

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

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

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

I talked my team into turning on compiler warnings again. Some how all warnings (-w) were disabled (don't ask...). Most of them are obvious but one of them is really annoying. I get it from my date and time classes which are used in lots of places. Story is really simple. Time is subclass of Date and both of them have their operators defined. What can be wrong with that? Here's the warning I get:

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

Perhaps somebody can link me the docs describing what each of SunStudio C++ compiler warnings mean? I can't find this... Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

漆黑的白昼 2024-07-19 09:56:18

我以前在 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-”,但这可能不是您想要的。

对于您的情况,另一种可能更好的解决方法是使操作员成为免费的朋友功能,但这可能会导致其他有趣的问题。

I've seen this before with the SunStudio compiler. Basically, you have a construct like this:

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

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

Due to the C++ scoping rules, ACTime::operator- hides ACDate::operator- in the context of an ACTime object. This is pretty normal but the SunStudio compiler warns about this problem as it might be a sign of a missing 'virtual' qualifier.

One workaround for this situation would be an explicit 'using ACDate::operator-' in ACTime's class declaration, but that might not be what you want.

Another, potentially better workaround for your situation is to make the operator- a free friend function, but that might lead to other interesting problems.

黑寡妇 2024-07-19 09:56:18

我可以帮助您解决该特定警告 - 它看起来很像 C++ FAQ Lite。 您是否偶然更改了 ACTime::operator- 使用 ACDate 中的参数类型?

I can help you with that particular warning - it looks a lot like this one from C++ FAQ Lite. Did you by chance change the type of argument that ACTime::operator- uses from the one in ACDate?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文