Lecture overview -- Keyboard shortcut: 'u'  Previous page: Function Overloading - Examples  -- Keyboard shortcut: 'p'  Next page: Vectors - examples -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 2 - Page 28 : 42
Notes about C++
Basic facilities
Vectors in C++

C++ has a flexible vector type, as an alternative to the C-like array facility

  • The C++ Programming Language: Page 52, 442
 

 

  • Vector characteristics:

    • A template class - type parameterized

    • Contiguously allocated - like a native array.

    • Not of fixed size like an array - the number of elements may be adjusted dynamically

    • Size and capacity:

      • Size: The actual number of elements in the vector

      • Capacity: The maximum number of elements before resizing is needed

    • With or without range checking: The programmer's choice

    • Obeys value semantics

      • If too expensive, pointers or references to vectors can be used

    • Traversed with use of iterators

      • Iterators can be used in a similar way as pointers, via overloading of operators

      • *iterator, iterator++, iterator+n, iterator1-iterator2

Go to exerciseUnderstand Vectors