I read below statements in Addison Wesley FAQs.
Beware: passing objects by value can
be dangerous in some situations. Often
it is better to pass objects by
reference-to-const than to pass them
by value. For example, pass-by-value
won’t work if the destination type is
an abstract base class and can result
in erroneous behavior at runtime if
the parameter’s class has derived
classes. However if the class of the
parameter is guaranteed not to have
derived classes, and if the function
being called needs a local copy to
work with, pass-by-value can be
useful.
How it can be erroneous behavior at runtime if destination type is an Abstract class and if the parameter’s class has derived class ?
Does copy constructor solve this problem ? If so, how ? Thank you.
EDIT: So, should the statement above be “erroneous behavior at compile time” ? Not “runtime” .
It won’t even compile. “Pass by value” means that you would try to copy the abstract class parts of the argument to a new object. But you cannot create an object with an abstract class as its mosted derived class because it’s abstract.