C++ (p2)

ducopubi's version from 2016-04-02 23:00


Question Answer
(T/F) Every class has a copy constructorTRUE
What does the default copy constructor provided by C++ do?it does a simple memberwise copy
When should you provide a copy constructor?if your class has a field that stores a pointer
What must your copy constructor have?should have a reference parameter
example of a class destructor Circle(), or also GradeBook
(T/F) a destructor has a return type?FALSE
Can a destructor have parameters?NO
Can a destructor be overloaded?NO, there can only be one in a class
what does the destructor do and does it destroy the object?does any clean up before memory is reclaimed by OS. Does not destroy object
What order are objects destroyed in?generally in reversed order they were constructed
When should a virtual destructor be included in a class?whenever a virtual method is in the class
What operators are always available for a class? // = // . // ->
what does the assignment operator do in a classdoes a memberwise copy (shallow copy)
What are some object handles?object name, pointer, and reference
what is the "this" pointerused in a class to refer to itself ( this -> / (*this). / return this; / return *this;
return this; ?returns a pointer to the object
what does //*this// do?used to dereference the "this" pointer
when must the this pointer be used?must be used to access a "shadowed" field (Ex: this-> name = name or (*this).name = name;
what type of inheritance is a derived class?"is a " base class (superclass)
Example of inheritance?class CommissionEmployeepublic Employee
what doesn't a derived class inherit from its base class?constructors and destructors
can a derived class directly access inherited members?only public and protected members from base class
Can a derived class have greater access to fields than the base class provides?NEVER
When does the derived class constructor execute?After its base class constructor
how to redefine an inherited member function?recreate the function header but modify the body of the function so it behaves differently (same as overriding but with static binding)
what is a overridden inherited member function?a "redefined" virtual function
What is dynamic binding?allows inherited member function executed to be based on the type of object
what is a pure virtual functionbasically a virtual function without a body (ex: virtual <function prototype> = 0 )
A class with a pure virtual function is a ?abstract class
a class without pure virtual functions is a ?concrete class
Downcasting allows what?allows access to derived class members that are not in the base class
what can a throw statement throw?Any Primitve type, an object, an exception class object
What are some exception class objectsruntime_error, logic_error
What are some logic_errorsinvalid_argument, length_error, out_of_range
runtime_error?overflow_error, underflow_error
how to catch any kind of exception?Catch(...)
Which 4 operators cannot be overloadedthe member access ( . ), pointer to member ( .* ) , scope resolution ( :: ) , conditional operator ( ?: )
which operators must be overloaded as non-static ?( ) , [ ], ->
(T/F) You can change the precedence of an operator?FALSE
(T/F) Associativity of an operator cannot be changed?TRUE
(T/F) "arity" (number of operands it uses) can be changedFALSE
When can a binary operator be overloaded with two parameterswhen it is overloaded as a non-member function
If a binary operator is overloaded as a member function it can have?one parameter