C.87: fix missing access specifiers (closes #1957)

This commit is contained in:
Sergey Zubkov
2022-08-08 15:39:14 -04:00
parent 9a95f97f44
commit 9d28e32999

View File

@@ -6653,6 +6653,7 @@ It is really hard to write a foolproof and useful `==` for a hierarchy.
class B { class B {
string name; string name;
int number; int number;
public:
virtual bool operator==(const B& a) const virtual bool operator==(const B& a) const
{ {
return name == a.name && number == a.number; 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. `B`'s comparison accepts conversions for its second operand, but not its first.
class D : B { class D : public B {
char character; char character;
public:
virtual bool operator==(const D& a) const 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 = ... B b = ...
D d = ... D d = ...
b == d; // compares name and number, ignores d's character 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;
d == d2; // compares name, number, and character d == d2; // compares name, number, and character
B& b2 = d2; B& b2 = d2;