
Class Features 119
int main()
{
CuboidMetal c1("Silver",3,4,12,13,1512,10.5);
CuboidMetal c2("Gold",2,3,6,7,7103,19.3);
c2=c1;
c2.DeterminePurity();
}
Output
Assignment operator Called
Metal type is Silver
Volume is 144
Density is 10.5
Metal Silver is pure.
The copy constructor and assignment operator implementation is generated by the compiler
for a class if it is not explicitly defined in a class implementation. If the class contains a pointer
variable, it is necessary to define the copy constructor and assignment operator for that class
to avoid bitwise copying which can create a dangling pointer and that can cause a serious
runtime error.
3.13