CS 340 - 2/26/13 Test on Thursday 4 or 5 questions - write some code & discuss an idea Parameter Types - pass-by-value (pass-by-address) - pass-by-reference - pass-by-const-reference Memory locations from the program point of view - stack / automatic - heap / dynamic (new, delete) - static TypeX* ptr1 = new TypeX(); TypeX* ptr2 = new TypeX; TypeX inst1; TypeX inst2(); TypeX arr[100000]; Classes data members and methods Constructors - initialization lists Complex::Complex (int im, int rl) : imag_ (im), real_ (rl) { } initialization versus assignment TypeX inst2 = inst1; TypeX inst2 (inst1); Operator Overloading - as a method vs as a function (make a friend?) c1 == 5.0) c1 == Complex(5.0) double(c1) == 5.0 5.0 == c1 op= should be overloaded as a method; otherwise the following could occur double value1; Complex c1 (5.0); value1 = c1; // if op= is overloaded as a // function which tranlates to: Complex temp (value1); temp = c1; Return by reference - most often done in a class when we want cascading operations c1 = c2 = c3 = c4; cout << "Text" << c1 << " more " << c2 << endl; q.insert(5).insert(7).insert(2); class Complex { double() const; // implements a type cast // from complex to double }; Complex::double() const { return real_; } The Big Three - Copy Constructor - destructor - operator= Templated functions template X max (X v1, X v2) { if (v2 < v1) return v1; else return v2; } int a, b, c; double e, f; a = max (b, c); Queue q1 a = max (e, c); Default parameters int findPos( int arr[], int size, int target, int start = 0); Overloading in general