mardi 8 décembre 2015

Resolve unsigned long / pointer ambiguity

Our legacy code is using RogueWave library. I am trying to construct a RWTime object from a 0 literal. However, anything I do doesn't seem to have an effect and the compiler still have two constructors to select from:

error: call of overloaded 'RWTime(int)' is ambiguous
   _time(static_cast<unsigned long>(0))
                                      ^
note: candidates are:
RWTime::RWTime(const tm*, const RWZone&)
     RWTime(const struct tm* ptm, const RWZone& zone = RWZone::local());
     ^
RWTime::RWTime(long unsigned int)
     RWTime(unsigned long s)
     ^
constexpr RWTime::RWTime(const RWTime&)
 class RW_DEPRECATE_TYPE("Use RWDateTime instead") RW_TOOLS_SYMBOLIC RWTime
                                                                     ^
constexpr RWTime::RWTime(RWTime&&)

I would like to use the unsigned long constructor, but I don't seem to be able to actually pass unsigned long. I tried:

_time(static_cast<unsigned long>(0))
_time((unsigned long)0)
_time(0UL)
_time(0)

but no effect. Maybe the problem is that a pointer has uintptr_t type, which is synonymous to size_t type which is synonymous to unsigned long. And then there are actually two constructors taking unsigned long.

EDIT: I checked the RWTime class documentation and they mention the problem: "The compiler can parse 0 as either an integer or a pointer. Since there is also a constructor that takes a pointer (to struct tm), if you want to construct a time from the unsigned long value 0, you must be explicit:

RWTime earlyTime((unsigned long)0);

However, for some reason it doesn't work for me (using c++11).

Aucun commentaire:

Enregistrer un commentaire