Constructors and Other Tools
Constructors and Other Tools
Constructors and
Other Tools
Learning Objectives
Constructors
Definitions
Calling
More Tools
const parameter modifier
Inline functions
Static member data
Vectors
Introduction to vector class
If no default constructor:
Cannot declare: MyClass myObject;
With no initializers
Call-by-reference desirable
Especially for "large" data, like class types
Protect argument
Use constant parameter
Also called constant call-by-reference parameter
More efficient
If too long actually less efficient!
Declared differently:
Syntax: vector<Base_Type>
Indicates template class
Any type can be "plugged in" to Base_Type
Produces "new" class for vectors with that type
Example declaration:
vector<int> v;
If efficiency critical:
Can set behaviors manually
v.reserve(32); //sets capacity to 32
v.reserve(v.size()+10); //sets capacity to 10 more
than size
Vector classes
Like: "arrays that grow and shrink"