Skip to content

Commit

Permalink
C.20: define a ctor to not imply we're forbidding all ctors
Browse files Browse the repository at this point in the history
closes #2212
  • Loading branch information
cubbimew committed Oct 3, 2024
1 parent 50afe02 commit dd57964
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions CppCoreGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -4878,6 +4878,7 @@ It's the simplest and gives the cleanest semantics.

struct Named_map {
public:
Named_map() : name("empty") {}
// ... no default operations declared ...
private:
string name;
Expand Down

3 comments on commit dd57964

@miemoe
Copy link

@miemoe miemoe commented on dd57964 Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this solution is confusing, as the term default operation is not well defined.
Is a default constructor a default operation?

I think that C.20 should have more details. It should show the inverse of C.21:
If there's no need to define any copy, move, or destructor function, then don't.

This explicitly leaves out constructors!

In the example I would like to see a constructor with a parameter:
Named_map(string mapName) : name(mapName) {}

@cubbimew
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, two constructors? (the example demonstrates the use of default and copy, so I gave it a default)
I think I agree about that "default operations" should be copy/move/dtor

@cubbimew
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edited again (with 1 ctor, and explanded 'default ops')

Please sign in to comment.