Download presentation
Presentation is loading. Please wait.
Published byIlene Dixon Modified over 9 years ago
1
Lecture 7
2
There are 2 types of libraries used by standard C++ The C standard library (math.h) and C++ The C++ standard template library Allows us to use containers and algorithms with any type Unlike java even primitives types are supported E.g. int, float, long
3
std::vector v; A resizable array of integers std::list lNodes; A doubly linked list of Node Pointers std::queue qPeople; A queue of Person objects std::deque dStoreQueue; A double ended queue of longs
4
T can be any value the vector has been instantiated with template void vector ::push_back(T const &item) { // resize if necessary new (&d_array[d_size++]) T(item); } Makes a copy Behaves the same way as primitives with functions i.e. myfunc(std::vector v) will make a copy.
5
std::vector p; for (int i =0; i < peoplelength; i++) { Person* prsn = new Person(); p.push_back(*prsn) ; //Calls class copy constructor }
6
.begin() – const iterator .end() – cost iterator
7
vector > array2D push_back(T) //add a value [-] Where ‘-’ is the integer index //access value by index .clear() and.erase(.begin(),.end() ); //clear the vector Note: Does not remove heap allocated memory such as that assigned with new
8
.insert(T).push_back(T) .begin(),.end() .front() ->Returns element in front .back()->Returns element behind .pop_back delete last element
9
Give us the potential to use templates that make our lives a whole lot easier Such as random number generators, tuples, threading and Signal/Slots Hard to understand until you know more about what Templates are Not 100% supported Each compiler (g++, visual c) has own specifications
10
Basics #includes using namespace std; OR used std:: e.g. std::endl; //new line Code that doesn’t compile (~30%) Syntax Passing correctly to functions C++ classes get/set/initialization lists/constructor/destructor C++ functions passing by reference and value Problem solving and logic question (~40%) const will feature a bit
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.