Study your flashcards anywhere!

Download the official Cram app for free >

  • Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off

How to study your flashcards.

Right/Left arrow keys: Navigate between flashcards.right arrow keyleft arrow key

Up/Down arrow keys: Flip the card between the front and back.down keyup key

H key: Show hint (3rd side).h key

A key: Read text to speech.a key


Play button


Play button




Click to flip

33 Cards in this Set

  • Front
  • Back
- also called the heap
- memory reserved for dynamic variables
- eliminates a dynamic variable pointed to by a pointer
- returns memory to the freestore
- after delete, the value of pointer is undefined
- delete [] a;
delete dynamic array
- creates copy of object
- has one parameter of the same type as the class
- that parameter must be call-by-reference, normally const
copy constructor
- create a copy of what each member variable is pointing to
- normally used when overloading = or defining copy constructor
deep copy
- the copy constructor or overloaded = simply copies the member variables from one object to another
- this is the default for compiler created = and copy constructor
- works fine if no pointers or dynamic data
shallow copy
- copy constructor, the = assignment operator, and the destructor
- if you need any, you need all three
- if missing, compiler will create, but it may not be how you want it
big three
- variable shared by all objects of the class
- allow some of the advantages of global variables without all the troubles
- can be private so that only objects of the class can directly access it
static members
- allow some of the advantages of global functions without all the troubles
- does not access the data of any object
- is still a member of a class
- cannot use anything that depends on a calling object
- cannot use any nonstatic variables or nonstatic member functions, unless the nonstatic variable or

function has a calling object that is a local variable or some object otherwise created in the

- commonly invoked as Class::staticFunction()
static functions
- declared like this: vector<type> v;
- is a template class
- cannot initialize the ith element using v[i] - you can only change an element that has already been

given a value
- to add an element to a vector for the first time, use the member function push_back
- v.size() returns the number of elements in a vector
- vector<int> v(10); constructor that initializes vector to the number of positions given by the

argument - the first ten elements are initialized to zero
- member function of a vector
- adds an element in the next available position
vector<double> sample;
- the complete definition of a member function is given in its class
- typically used for very short functions
- the code for the function is inserted at each location where the function is invoked
- go against the principle of encapsulation
- for long functions, the inline version can actually be less efficient
- use the keyword inline before declaration and definition
inline functions
- nonmember functions that have the privs of member functions
- not a member function of the class, but has access to private members
- name it as a friend function in the class definition
- use the keyword friend
- most commonly are overloaded operators
- can be a friend of more than one class
- provides automatic type conversion
friend functions
- If the class F is a friend of the class C, then every member function of the class F is a friend of

the class C.
- it is typical for the classes to reference each other
friend classes
- at least one parameter must be of a class type
- most operators can be overloaded as a member of the class, a friend of the class, or a nonmember,

- the following operators can only be overloaded as (nonstatic) members of the class: =, [], ->, and

- you cannot create a new operator
- you cannot change the number of arguments that an operator takes
- you cannot change the precedence of an operator
- the following operators cannot be overloaded: dot. scope:: sizeof question? the .*
- cannot have default arguments
rules on overloading operators
- automatic type conversion of all arguments
- fullAmount = 25 + baseAmount // legal
nonmember nonfriend operator overloading
- gives you the efficiency of bypassing accessor and mutator functions and directly accessing member

- when you overload a binary operator as a member operator, the two arguments are no longer

symmetric. one is a calling object, and only the second "argument" is a true argument. this is not

only unaesthetic but also has a very practical shortcoming. any automatic type conversion will only

apply to the second argument.
- fullAmount = 25 + baseAmount; // illegal
member operator overloading
- best of both worlds (nonmember nonfriend operator overloading & member operator overloading)
- automatic type conversion of all arguments
- gives you the efficiency of bypassing accessor and mutator functions and directly accessing member

friend operator overloading
- if your class definition contains the appropriate constructors, the system will perform certain

type conversions automatically.
- ex. fullAmount = baseAmount + 25;
automatic type conversion via constructors
- ends a switch statement
- merely ends one loop iteration
- a type whose values are defined by a list of constants of type int
- handy for defining a list of identifiers
- used like a void function that takes one call-by-value parameter of type bool
- #include <cassert>
- an assertion is either true or false
- a macro is very similar to an inline function
- if the precondition is not satisfied, your program will end and an error message will be output
- assert();
- you can turn assert off with #define NDEBUG
assert macro
- Driver: a special program to do testing
- Stub: simplified version of a missing or untested function
stubs and drivers
- if you have a member function that should not change the value of a calling object, you can mark

the function with the const modifier
- the computer will issue an error message if your function code changes the value of the calling

const function modifier
- if you are using a call-by-reference parameter and the function does not change the value of the

parameter, you can mark the parameter so that the compiler knows that the parameter should not be

- place the modifier const before the parameter type
const call-by-reference parameter
- can be used as if they were literal values of type string
- s3 = "Hello Mom!";
- strings in double quotes
- just an array of characters
- terminated by '\0' null character
- char aString[10]; strcpy(aString, "Hello"); // legal
- can be output with <<
- size of first dimension is not given (because it's a pointer?)
multidim array parameters for function headings
- automatic type casting of quoted strings to type string
- strcpy
- strcmp
- strcat
- strlen
- created using the new operator
- p1 = new int;
- has no identifier
- created and destroyed while the program is running
dynamically allocated variables
- memory address
- can be stored in a variable
- cannot store in variable of type int or double, must have pointer type
- must be asterisk before each pointer declaration
- the asterisk (*) is called the dereferencing operator. it produces the variable to which it points
- the ampersand (&) in front of an ordinary variable produces the address. it is called the

address-of operator
- double *p, v; p = &v; *p = 9.99;
- size not specified when you write the program
- size determined while the program is running
- created with new
- d = new double[10];
int arraySize;
cout << "How many?";
cin >> arraySize;
intPtr a;
a = new int[arraySize];
delete [] a;
pointer arithmetic
- allows you to read in one character at a time
- takes one argument, should be char
- will read blank or new line if that is next character