views:

245

answers:

2

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!

+1  A: 

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?

Kristo
+2  A: 

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.

Timo Geusch
Yet another option would be to use private inheritance. Also, I think the return types are wrong: the difference between two dates is an interval in days, between two times an interval in (fractions) of seconds.
MSalters