From 9d28e32999d75b2d3b4970172c9146705a13810c Mon Sep 17 00:00:00 2001 From: Sergey Zubkov Date: Mon, 8 Aug 2022 15:39:14 -0400 Subject: [PATCH] C.87: fix missing access specifiers (closes #1957) --- CppCoreGuidelines.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index b172a7c..bdf01dc 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -6653,6 +6653,7 @@ It is really hard to write a foolproof and useful `==` for a hierarchy. class B { string name; int number; + public: virtual bool operator==(const B& a) const { return name == a.name && number == a.number; @@ -6662,11 +6663,12 @@ It is really hard to write a foolproof and useful `==` for a hierarchy. `B`'s comparison accepts conversions for its second operand, but not its first. - class D : B { + class D : public B { char character; + public: virtual bool operator==(const D& a) const { - return name == a.name && number == a.number && character == a.character; + return B::operator==(a) && character == a.character; } // ... }; @@ -6674,7 +6676,7 @@ It is really hard to write a foolproof and useful `==` for a hierarchy. B b = ... D d = ... b == d; // compares name and number, ignores d's character - d == b; // error: no == defined + d == b; // compares name and number, ignores d's character D d2; d == d2; // compares name, number, and character B& b2 = d2;