Regarding the error error C2059: syntax error : 'return'
, this is the way to fix this specific error:
return stringOutput ? "never" : sObjectMgr->FindCreature(Guid)->GetCreatureData()->spawntimesecs;
the ?:
operator is an expression, and each argument of the operator should be an expression. return
is a statement. not an expression.
As an expression, ?:
has exactly single type. but "never"
and spawntimesecs
are unrelated types. The compiler cannot handle that. these two values does not belong in the same ?:
expression.
You can probably use a union, but it is not recommended.
A better solution will not use template at all, since you do not use the type parameter in any polymorphic way:
float GetTimeDeadFloat(uint64 Guid)
{
return find(Guid)
? dieTracker.find(Guid)->second.seconds
: sObjectMgr->FindCreature(Guid)->GetCreatureData()->spawntimesecs;
}
string GetTimeDeadString(uint64 Guid)
{
return find(Guid)
? timeToString(dieTracker.find(Guid)->second.seconds)
: "never";
}
bool find(uint64 Guid) {
for(map<uint32, TrackInfo>::iterator itr = dieTracker.begin(); itr != dieTracker.end(); ++itr) {
if(itr->second.GUID == Guid)
return true;
}
return false;
}
string timeToString(float seconds) {
string res = timeToString(seconds % 3600 / 60, "Minutes");
res += timeToString(seconds % 86400 / 3600, "Hour");
res += timeToString(seconds / 86400, "Day");
if (secs || res.length() == 0)
res += numToString(seconds % 60, "Second");
res += "ago";
return res;
}
string numToString(uint64 num, string type) {
ostringstream ss;
if (num)
ss << num << " " << type << (num != 1) ? "s" : "" << " ";
return ss.str();
}