An unofficial, read-only Hacker News reader.

In C++, = default and {} are not the same constructor (opens external site)

131 points by surprisetalk 4 days ago | lemire.me | 198 comments on HN

View full thread · View on Hacker News

Comment thread (2)

  1. Rust has a Default trait, if your type Goose has a Default then

    let foo: Goose = Default::default();

    Those "primitive" types have a Default, the integers default to zero, as do the floating point types, bool defaults to false, I believe an empty string is the default string (in both the sense that's the default for String, and the default for str, the string slice reference roughly analogous to C++ string_view)

    Some things don't have a sane default, just as those things wouldn't provide a zero argument constructor in C++. There isn't a default file descriptor, a default network socket, and so on and so those types do not implement Default

    Replies (1)
    1. That makes sense, thanks!