You are viewing a single comment's thread. Return to all comments →
"The type of an integer literal is the first of the corresponding list in Table 6 in which its value can be represented."
And Table 6, for literals without suffixes and decimal constants, gives:
long long int
So, without the cast, the literal 0 can be represented as int, so accumulate uses int as the type for accumulation.
I think there is another way , to avoid the static_cast(0) , and do it by simply accumulate(....,0L);
If I remember correct (I am too lazy to search in books or google now to verify!) the L forces the number to be interpreted as long long.
L is the suffix for long just like LL is the suffix for long long. Weird but not confusing. accumulate(....,0LL) avoids the static cast.