Skip to content

Chapter 2 exercise answer bug #267

Open
@ZenoTan

Description

@ZenoTan

The exercise answer could not handle negative values:

template<typename ... T>
auto average(T ... t) {
    return (t + ... ) / sizeof...(t);
}
int main() {
    std::cout << average(1, 2, 3, 4, 5, -6, -7, -8, -9, -10) << std::endl;
}

It would return 1844674407370955159 on my side since it deduced the return value to be unsigned int.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions