CS 105: C++
Project 6 Required Concepts
C++: Chapter 5-8

  1. Learn the two simple rules for understanding public vs private inheritance described in this discussion.
  2. Given an existing class, be able to write a complete definition of a (simple) derived class, including the addition of new members during the derivation.  How do you set access control (public vs private) for the inherited members?  How do you set access control for the new members?

  3. Under some circumstances, a pointer to one class can be set to point to an object of another class.  Can a pointer to a base class be set to point to a derived class?  Can a pointer to a derived class be set to point to a base class?

  4. When one class is derived from another, but the derivation access level is not specified, what is the default?  Is this what you are likely to want or not?

  5. C already had mechanisms for allocating and deallocating memory (malloc and free).  What are the C++ replacements for these, and what useful things do they do that malloc and free do not do?

  6. Be able to write (with correct syntax) simple C++ code to allocate and deallocate memory.  For example, can you write the C++ equivalents of the following statements?

    float *fp = malloc(sizeof(float));
    free(fp);

  7. Be able to write (with correct syntax) simple C++ code to allocate and deallocate memory for an array.  For example, can you write the C++ equivalents of the following statements?

    float *fa = malloc(sizeof(float) * 10);
    free(fa);

  8. Be able to allocate and deallocate memory for a class instance in C++.  For example, can you complete the following statement so that bp points to a dynamically allocated instance of class Bar?  Can you write code to deallocate that instance?

    Bar *bp = ________________ ;

  9. References in C++ are a very useful variation on pointers.  Learn how to use them, including the rules for their syntax.  For example, can you rewrite the following code to use references instead of pointers?

    #include <iostream>
    using namespace std;

    void plus_5(int *ip) {
    *ip = *ip + 5;
    }

    int main() {
    int n = 3;
    plus_5(&n);
    cout << n << '\n';
    }
  10. What's wrong with the following function?

    int& foo() {
    int n;

    n = 10 / 2;
    return n;
    }



Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.