Unofficial Hacker News companion — reply notifications without a password. · Learn more

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

131 points by surprisetalk 5 days ago | lemire.me | 200 comments on HN | Vote on HN (opens Hacker News) |

View full thread · View on Hacker News

Comment thread (1)

  1. That's really the problem with constructors being anonymous (or equivalently, having exactly the same name as the class they belong to), isn't it? In e.g. Object Pascal the constructors are special methods (they have to be marked with the keyword 'constructor'), but they have names, and you can have several of them with different names.

        auto v = std::vector::from_values("foo", "bar");
        // v is std::vector<char*>
    
        auto w = std::vector::from_iters("foobar", "foobar" + 3);
        // w is std::vector<char>