You can, but you must declare it static and const :
struct Timer { static const auto start = 0; };
Working example at Coliru .
With this limitation, you cannot have start as a non-static member, and you cannot have different values ββin different objects.
If you need different start types for different objects, it is better to have your class as a template
template<typename T> struct Timer { T start; };
If you want to deduce type T , you can make a factory-like function that does type inference.
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)}; }
Living example .
Mark garcia
source share