PROGRAMMING POINTERS, LESSON 16
Syntax/correctness
issues
16-1 Remember that an array starts at position 0. Avoid iterating past the last value in the array. This will cause a value-range error and the program will halt.
16-2 The templated apvector class can be used with any data type which has a default constructor. The built-in data types (int, double, char, bool) all have default constructors.
Formatting
suggestions
None
Software
engineering
16-3 Carefully consider what type of parameters to use when passing arrays.
If the changes made to a parameter need to be reflected back to the actual parameter, use a reference parameter. Example:
void doSomething (apvector<int> &data);
If you want to protect an actual parameter from any changes, but want the efficiency of reference parameters, use a const reference parameter.
void doSomething (const apvector<int> &data);
When you use an array as a value parameter, a local copy is made within the local scope of the function. This requires more memory and processing time.
void doSomething (apvector<int> temp); // temp will be a copy of the actual parameter