include::../description.adoc[]

== Noncompliant Code Example

----
class Fruit {
  protected:
    Season ripe;
    static Color flesh;

  // ...
};

class Raspberry : public Fruit {
  private:
    bool ripe;  // Noncompliant
    static Color FLESH; // Noncompliant
};
----

== Compliant Solution

----
class Fruit {
  protected:
    Season ripe;
    static Color flesh;

  // ...
};

class Raspberry : public Fruit {
  private:
    bool ripened;
    static Color FLESH_COLOR;

};
----

== Exceptions

This rule ignores same-name fields that are ``++static++`` in both the parent and child classes. This rule ignores ``++private++`` parent class fields, but in all other such cases, the child class field should be renamed.


----
class Fruit {
  private:
    Season ripe;
  // ...
};

class Raspberry : public Fruit {
  private:
    Season ripe;  // Compliant as parent field 'ripe' is anyway not visible from Raspberry
  // ...
};
----

or


----
class Fruit {
  public:
    Season ripe;
  // ...
};

class RedFruit : private Fruit {
};

class Raspberry : public RedFruit { // RedFruit inherits from Fruit privately
  private:
    Season ripe;  // Compliant as parent field 'ripe' is anyway not visible from Raspberry
  // ...
};
----

== See

* https://github.com/isocpp/CppCoreGuidelines/blob/036324/CppCoreGuidelines.md#es12-do-not-reuse-names-in-nested-scopes[{cpp} Core Guidelines - ES.12] - Do not reuse names in nested scopes

ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]
