== Why is this an issue?

Overriding the default parameter value inherited from a parent class will lead to unexpected results when the child class is referenced from a pointer to the parent class.

=== Noncompliant code example

[source,cpp,diff-id=1,diff-type=noncompliant]
----
enum E_ShapeColor {E_RED, E_GREEN, E_BLUE};

class Shape
{
public:
  virtual void draw(E_ShapeColor color = E_RED) const
  {
    ...
  }
};

class Rectangle : public Shape
{
public:
  virtual void draw(E_ShapeColor color = E_BLUE) const override // Noncompliant
  {
   ...
  }
};

int main() {
  Shape *shape = new Rectangle{};
  shape->draw();  // unexpectedly calls Rectangle::draw(RED)
}
----

=== Compliant solution

[source,cpp,diff-id=1,diff-type=compliant]
----
enum E_ShapeColor {E_RED, E_GREEN, E_BLUE};

class Shape
{
public:
  virtual void draw(E_ShapeColor color = E_RED) const
  {
    ...
  }
};

class Rectangle : public Shape
{
public:
  virtual void draw(E_ShapeColor color) const override
  // OR: virtual void draw(E_ShapeColor color = E_RED) const override
  {
    ...
  }
};

int main() {
  Shape *shape = new Rectangle{};
  shape->draw(); // expectedly calls Rectangle::draw(RED)
}
----

== Resources

* MISRA {cpp} 2008, 8-3-1 - Parameters in a overriding virtual function shall either use the same default arguments as the function they override, or else shall not specify any default arguments.

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Remove the default value for parameter "xxx" or set it to the same value as in the base class.


'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]

endif::env-github,rspecator-view[]
