Different return types with same function I'm implementing my own time unit class. This class provides a function for fetching a specific time value (milliseconds, seconds etc.). In order to prevent defining several get() functions for each time unit, I tried to implement a single function to serve this purpose.

typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned long long u_ll;
typedef u_ll DAYS_DTYPE;
typedef u_char HOURS_DTYPE;
typedef u_char MINUTES_DTYPE;
typedef u_char SECONDS_DTYPE;
typedef u_short MILLISECONDS_DTYPE;

// used class members; max. values are handled class-internal
DAYS_DTYPE          m_days;         // max.: 18.446.744.073.709.551.615
HOURS_DTYPE         m_hours;        // max.: 23
MINUTES_DTYPE       m_minutes;      // max.: 59
SECONDS_DTYPE       m_seconds;      // max.: 59
MILLISECONDS_DTYPE  m_milliseconds; // max.: 999

// class-internal enum
enum TimeUnit { Milliseconds, Seconds, Minutes, Hours, Days };

// used member function
template &lt;typename T&gt;
T getTime(TimeUnit unit)
{
    switch (unit)
    {
    case Milliseconds: return m_milliseconds;
    case Seconds: return m_seconds;
    case Minutes: return m_minutes;
    case Hours: return m_hours;
    case Days: return m_days;
    default:
        break;
    }
}


In order to fetch a specific time unit I have to use sth. like this:

getTime&lt;MILLISECONDS_DTYPE&gt;(Time::Milliseconds))


Is this approach acceptable? In case it's not, what should I change?
I prefer something like this, as its less to type and compile-time, you probably always know what kind of time you need on compile-time and even if not you can hack around that problem, so:

template&lt;TimeUnit time&gt;
struct TimeUnitImpl
{ using type = decltype(m_milliseconds); };

template&lt;&gt;
struct TimeUnitImpl&lt;Seconds&gt;
{ using type = decltype(m_seconds); };

template&lt;&gt;
struct TimeUnitImpl&lt;Minutes&gt;
{ using type = decltype(m_minutes); };

template&lt;&gt;
struct TimeUnitImpl&lt;Hours&gt;
{ using type = decltype(m_hours); };

template&lt;&gt;
struct TimeUnitImpl&lt;Days&gt;
{ using type = decltype(m_days); };

// used member function
template &lt;TimeUnit unit = Seconds&gt;
typename TimeUnitImpl&lt;unit&gt;::type getTime()
{
    switch (unit)
    {
    case Milliseconds: return m_milliseconds;
    case Seconds: return m_seconds;
    case Minutes: return m_minutes;
    case Hours: return m_hours;
    case Days: return m_days;
    default:
        break;
    }
}


In order to fetch a specific time unit you would have to use something like this: 

getTime&lt;Time::Milliseconds&gt;()


Try it online!

In order to keep a "good style" I would change the function name here, too. Probably simply to time rather than getTime, that get-prefix is pretty much useless here.

But anyways, you might consider just using getTimeMilliseconds or something like that.