1/13
Flashcards created from lecture notes on Constructor, Destructor, Operator and Function Overloading.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
__: Making an instance of the class/type. Instances have allocated memory to store specific information. There can be multiple identical instances of the same type.
Instantiation
For each class instance, is when it is created, sets up necessary stuff; and is when it is destroyed (freed), cleans up the stuffs.
Constructor; Destructor
__ are special member functions used to initialize the object, and they have the same name as the class and no return type, but can take different arguments.
Constructors
The __ is a special cleanup member function that is called when the object is destroyed, its name is '~' + the class name, and takes no arguments and has no return type.
Destructor
A __ is a constructor that initializes an object using another instance of the same class. ClassName(const ClassName& obj);
Copy constructor
A __ is implicitly created by the compiler if there is no user-defined copy constructor, and performs a member-wise copy between objects, where each member is copied by its own copy constructor.
Default copy constructor
Note: A __ is implicitly created by compiler only if there is no user-defined constructor.
Default constructor
In member functions, __ can be used to point to the instance itself, and is useful when you need to return the pointer or reference to the instance.
this
__ pertain to the class, not to individual instances. Static member variables are shared among all instances. Static member functions do not have an associated instance, so you can only see the static member variables.
Static members
Functions that do the same thing but using different argument lists are known as __.
Function Overloading
C++ allows you to redefine built-in operators like +, -, *, … An __ is a special function form to overload an operator. operatorX(arguments…);
Operator function
A __ is implicitly created by compiler if there is no user-defined assignment operator, and does a member-wise copy between objects, where each member is copied by its own assignment operator.
Default assignment operator
__ allow binary search for fast lookup, addition, and removal of data items
BST
__ rule: The left subtree of a node contains only nodes with keys smaller than its key. The right subtree of a node contains only nodes with keys greater than its key. The left and right subtree each must also be a BST. There must be no duplicate nodes.
BST