You can, but you have to declare it static
and const
:
struct Timer {
static const auto start = 0;
};
With this limitation, you therefore cannot have start
as a non-static member, and cannot have different values in different objects.
If you want different types of start
for different objects, better have your class as a template
template<typename T>
struct Timer {
T start;
};
If you want to deduce the type of T
, you can make a factory-like function that does the type deduction.
template<typename T>
Timer<typename std::decay<T>::type> MakeTimer(T&& startVal) { // Forwards the parameter
return Timer<typename std::decay<T>::type>{std::forward<T>(startVal)};
}