An abstract class represents the interface part of a hierarchy. Invoking the copy constructor from the top of such a hierarchy bypasses the underlying implementation resulting in only the base sub-objects being copied.


== Noncompliant Code Example

----
class B1
{
public:
  B1 ( );
  B1 & operator= ( B1 const & rhs ); // Noncompliant
};

class D1 : public B1
{
public:
  D1 & operator= ( D1 const & rhs );
private:
  int32_t member;
};

void f1( B1 & b1, B1 & b2 )
{
  b1 = b2; // operator in B1 will be called: field "member" will not be copied
}
----


== Compliant Solution

----
class B1
{
public:
  B1 ( );
  protected B1 & operator= ( B1 const & rhs ); // Compliant
};

class D1 : public B1
{
public:
  D1 & operator= ( D1 const & rhs );
private:
  int32_t member;
};

void f1( B1 & b1, B1 & b2 )
{
  b1 = b2; // Compiler error will be reported
}
----


== See

* MISRA {cpp}:2008, 12-8-2 - The copy assignment operator shall be declared protected or private in an abstract class.


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

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