Skip to content

Comment on C++ to Rust Phrasebookparent

Comments

There are easy ways to implement stuff like enums with members in C++, just put an anonymous enum inside a class/struct, its possible but marked as not possible.

This guide does exactly that in C++ for methods on enums.

For members, won't this result in all instances of an "enum" having all fields? That's not really comparable to Rust enums, if that's what you mean.

For members, won't this result in all instances of an "enum" having all fields? That's not really comparable to Rust enums, if that's what you mean.

Rust enums are not enums, they are tagged unions and there is a C++ equivalent, std::variant which was discussed. It’s not got nice tooling around it like match but it exists and can be used identically.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.