Skip to content

Instantly share code, notes, and snippets.

@fish2000
Last active November 20, 2023 12:03
Show Gist options
  • Save fish2000/7949ed279a6ce41302df371e1833f32c to your computer and use it in GitHub Desktop.
Save fish2000/7949ed279a6ce41302df371e1833f32c to your computer and use it in GitHub Desktop.

Revisions

  1. fish2000 revised this gist Mar 4, 2020. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions CppCoreGuidelines.md
    Original file line number Diff line number Diff line change
    @@ -6190,6 +6190,8 @@ A *polymorphic class* is a class that defines or inherits at least one virtual f

    ##### Example

    ```c++

    class B { // GOOD: polymorphic class suppresses copying
    public:
    B(const B&) = delete;
    @@ -6211,6 +6213,8 @@ A *polymorphic class* is a class that defines or inherits at least one virtual f
    D d;
    f(d);

    ```

    ##### Note

    If you need to create deep copies of polymorphic objects, use `clone()` functions: see [C.130](#Rh-copy).
    @@ -6238,6 +6242,8 @@ The compiler is more likely to get the default semantics right and you cannot im

    ##### Example

    ```c++

    class Tracer {
    string message;
    public:
    @@ -6250,6 +6256,8 @@ The compiler is more likely to get the default semantics right and you cannot im
    Tracer& operator=(Tracer&&) = default;
    };

    ```

    Because we defined the destructor, we must define the copy and move operations. The `= default` is the best and simplest way of doing that.

    ##### Example, bad
  2. fish2000 revised this gist Mar 4, 2020. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions CppCoreGuidelines.md
    Original file line number Diff line number Diff line change
    @@ -6165,6 +6165,8 @@ A *polymorphic class* is a class that defines or inherits at least one virtual f

    ##### Example, bad

    ```c++

    class B { // BAD: polymorphic base class doesn't suppress copying
    public:
    virtual char m() { return 'B'; }
    @@ -6184,6 +6186,8 @@ A *polymorphic class* is a class that defines or inherits at least one virtual f
    D d;
    f(d);

    ```

    ##### Example

    class B { // GOOD: polymorphic class suppresses copying
  3. fish2000 created this gist Mar 4, 2020.
    22,516 changes: 22,516 additions & 0 deletions CppCoreGuidelines.md
    22,516 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.