From 8f1ba8db4f5ff5765ee7b316106ee1f9fefea006 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 4 Apr 2022 12:44:23 +0200 Subject: [PATCH] Documentation: Clarify text about virtual/override/final --- Documentation/CodingStyle.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Documentation/CodingStyle.md b/Documentation/CodingStyle.md index 2955fb5534a..9415ff8b50e 100644 --- a/Documentation/CodingStyle.md +++ b/Documentation/CodingStyle.md @@ -554,7 +554,7 @@ catdog_widget.on_click = [&] { ### Overriding Virtual Methods -The declaration of a virtual method inside a class must be declared with the `virtual` keyword. All subclasses of that class must either specify the `override` keyword when overriding the virtual method or the `final` keyword when overriding the virtual method and requiring that no further subclasses can override it. +The declaration of a virtual method inside a class must be declared with the `virtual` keyword. All subclasses of that class must also specify either the `override` keyword when overriding the virtual method, or the `final` keyword when overriding the virtual method and requiring that no further subclasses can override it. ###### Right: @@ -566,7 +566,7 @@ public: class Student : public Person { public: - virtual String description() override { ... }; // This is correct because it only contains the "override" keyword to indicate that the method is overridden. + virtual String description() override { ... }; // This is correct because it contains both the "virtual" and "override" keywords to indicate that the method is overridden. } ``` @@ -579,7 +579,7 @@ public: class Student : public Person { public: - virtual String description() final { ... }; // This is correct because it only contains the "final" keyword to indicate that the method is overridden and that no subclasses of "Student" can override "description". + virtual String description() final { ... }; // This is correct because it contains both the "override" and "final" keywords to indicate that the method is overridden and that no subclasses of "Student" can override "description". } ``` @@ -594,7 +594,7 @@ public: class Student : public Person { public: - String description() override { ... }; // This is incorrect because it uses only the "override" keywords to indicate that the method is virtual. Instead, it should use both the "virtual" and "override" keywords. + String description() override { ... }; // This is incorrect because it uses only the "override" keyword to indicate that the method is virtual. Instead, it should use both the "virtual" and "override" keywords. } ``` @@ -606,7 +606,7 @@ public: class Student : public Person { public: - String description() final { ... }; // This is incorrect because it uses only the "final" keywords to indicate that the method is virtual and final. Instead, it should use both the "virtual" and "final" keywords. + String description() final { ... }; // This is incorrect because it uses only the "final" keyword to indicate that the method is virtual and final. Instead, it should use both the "virtual" and "final" keywords. } ``` @@ -618,7 +618,7 @@ public: class Student : public Person { public: - virtual String description() { ... }; // This is incorrect because it uses the "virtual" keyword to indicate that the method is overridden. + virtual String description() { ... }; // This is incorrect because it uses only the "virtual" keyword to indicate that the method is overridden. } ```