Bowl of cherries
Is life just a bowl of cherries?
cs_logo

CS 626 Object-Oriented Principles and Practices / C++
Frequently Asked Technical Questions

Spring Trimester 2013
Email A.Fischer at work Email A.Fischer at home
Course Home Page
Administrative FAQs
Technical FAQs
Lecture Notes
Programming Project
Chapters from the Text
Code Examples

<< Back
Cherry tree
May your efforts bear fruit.
Cherry blossoms
Cherry tree in the spring.
Cherry banch
  1. Advice on using a constructor to read a data file:
    If your constructor finds an eof condition at any time before it has completed reading data for the object under construction, set one field of the object to 0 or NULL and do nothing more. If possible, read all necessary data before allocating any new memory. It is a real mess when an object is half-allocated and must be deleted.

  2. Question: I am having trouble reading string input. An integer is given on one input line and a string is on the next line of input. Here is my code:

    1. int k;
    2. char buff[100];
    3. cin >> k;
    4. cin.getline(buff, 100);
    After "cin >> k", there is a CR in the stream, and when the compiler gets to "cin.getline()" (line4), it thinks the CR is an input, so, the CR gets copied to buff. So I never get a chance to enter a string.

    Answer: get() and getline() do not clear out leading whitespace. They are always used as follows:
    1. cin >> ws; // clear out all leading whitespace
    2. cin.getline(buff, 100);
    3. length = cin.gcount(); // the 1+strlen of the string you just read.
  3. Question: Please explain const again!
    Answer: A summary of const

  4. Question: When a class is publicly derived, it won't inherit the private members of its base class, will it?

    Answer: Yes, it will inherit all members of the base class. However, the private members are not "visible". The private data members take up space and get initialized just as in the base class, but the functions in the derived class cannot use them. The functions in the base class can be applied to the whole object, and they do "see" and can use the private parts.

    Question: Is it true that the private members of the derived class are only visible to its class, not even its base class?

    Answer: That is true because no members of the derived class are visible to the functions in the base class.

  5. Question: I am having trouble understanding ctors.
    Answer: About ctors

  6. Question: I have a dozen questions about Hangman.
    Answer: About Hangman

Photographs by Michael and Alice Fischer, from our home in Hamden. Last updated: 3/31/13