An unofficial, read-only Hacker News reader. Join the beta →

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

129 points by surprisetalk 2 days ago | lemire.me | 198 comments on HN

View full thread · View on Hacker News

Comment thread (2)

  1. Stroustrup does not write all of his code according to the JSF rules. Avoiding dynamic allocation for example isn't appropriate for all apps, especially if one ends up reinventing it poorly.

    One thing he does do consistently, and it baffles me why most other C++ codebases do not, is `using namespace std`. It's the standard library, if there's any names that ought to be used unqualified, it's those.

    Replies (1)
    1. The C++ Core Guidelines simultaneously tell you that it's fine to do this and that doing it risks (as so often in C++) weird hard-to-understand compiler errors - because if there's any names that should be unqualified it's your names, not those from the stdlib.

      Unlike say, Rust, C++ chooses to just shove most things directly in std. You were probably expecting vector, sort and list and if you're paying attention perhaps integral and format but did you expect get_money? invocable? hive? Because those are all defined too. On average your program probably uses several of these universally reserved identifiers, and more get added in each C++ version. Yay.