Algorithms and Data Structures (in C++) Chapter 1 (Cont)

Card Set Information

Algorithms and Data Structures (in C++) Chapter 1 (Cont)
2014-01-23 18:02:58
Algorithms Computer Programminglgo
Chapter 1 cont.
Show Answers:

  1. What is the default visibility of class members
  2. What is an initialization list used for? How is it declared?
    • It initializes data members directly. If a data member is an object without a zero-initialization constructor than an initialization list must be used. 
    • Class Blah(){public: explicit Blah( int m = 0) :member{ m }{}}
  3. What is the purpose of the explicit constructor ( i.e. explicit ClassName(){})?
    It tells the compiled not to allow implicit type conversions -- especially helpful for classes with one-parameter constructors.
  4. How do you tell the compiled that a member function is an accessor?
    With the keyword 'const' after the closing parenthesis
  5. Function declarations can contain the 'const' keyword in three different contexts. What are they.
    • 1) Specifying that the function will return-by-const-ref (const int & functionName(){})
    • 2) When the function is an accessor (int functonName() const {})
    • 3) And in the parameter to indicate that the param will be a pass-by-const-ref rather than a copy (pass-by-value)
  6. What does the keyword mutable mean?
    Data members can be declared mutable to cancel out 'const - ness'.
  7. What is the 'Scope Resolution Operator'?
    Indicates what class the member function is apart of. (Namespace) (Uses '::')
  8. What are the 'big five' functions that are included by default in any class?
    1) Destructor 2) Copy Constructor 3) Move Constructor (For R-Values) 4) Copy Assignment Constructor 5) Move assignment Constructor.
  9. How do you pass a function as a parameter.
    By using a function-object; a function wrapped in a class.
  10. What is the 'Operator()' known as and how is it useful in function-objects?
    It is called the 'function call operator'. When being invoked the word 'operator' can be omitted; meaning an instance of a function object with the 'function call operator' can be overloaded, when given a meaningful name can yield something like: isLessThan(obj2, obj3)