To understand why the revised analyze_train
program fails, you need
to learn more about how the C++ compiler handles class-object arguments.
Recall that, because C++ is a call-by-value language, C++ programs ordinarily reserve a memory chunk for each parameter whenever a function is called. Then, C++ programs copy evaluated arguments into those chunks of memory:
Memory reserved for parameter | v *-----*-----*-- Evaluated argument -----------> | | | *-----*-----*---
If an argument consists of a single variable, a C++ program copies the value of that variable into the reserved memory chunk:
Memory reserved for Memory reserved for parameter argument variable | | | v v *-----*-----*-- Copy *-----*-----*-- | | | -------------> | | | *-----*-----*--- *-----*-----*---