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 (4)

  1. With guaranteed RVO you could do something like this (pseudo-C):

       struct FooBase { ... }
       fn make_foo_base(...) -> FooBase
       struct Foo { base : FooBase; ... }
       fn make_foo(args...) -> Foo {
          return { .base = make_foo_base(...), ... }
       }
    Replies (1)
    1. How is it ensured that make_foo will actually call make_foo_base?
      Replies (2)
      1. You are right, sorry, lost track or the thread.
      2. Because it needs a FooBase to give as the value for .base or the struct initialization isn't valid because it doesn't give values for all the members?