logoalt Hacker News

aw1621107 • today at 4:38 PM • 2 replies • view on HN

Both those feel a bit like circular arguments? They need constructors because that's how they are currently defined, but that doesn't say anything about whether they could also be defined without constructors.

The latter was what I was interested in, and I apologize for not making that clear. For instance, in Rust terms both those seem replaceable in principle via calls to appropriate trait functions like Default::default() or From::from().


Replies

0x457 • today at 8:20 PM

Well, in Rust, you can't make your own Box without using #[lang = "owned_box"] and #[fundamental], plus it has special orphan rule handling.

The question is, at least for me, do you really miss out on anything by not having an ability to do so? I think you miss anything, but you gain a lot.

pjmlp • today at 5:39 PM

Nope, because you also want C types, that now are C++ types by virtue of using a C++ compiler, to also share similar behaviours.

Which is why the only difference between a struct and a class, is the default access method.

Thus that C file could be made extensible in C++, with zero code changes on the call sites.

➕ show 2 replies