C++ Chapter 10: Structures & Classes

Card Set Information

C++ Chapter 10: Structures & Classes
2012-04-03 21:49:30
structures classes destructors friends

C++ Chapter 10: Structures & Classes
Show Answers:

  1. An Object is a variable that has member functions, and a Class is a data type whose variables are objects.
  2. The definition of a Class is a data type definition that describes two things:
    1. What kinds of values the variables can hold.
    2. What the member functions are.
  3. A Structure is an object without any member functions.
  4. The name of a structure type is called a structure tag.
  5. The identifiers declared inside the braces { } are called member names and a structure type definition ends with both a brace, }, and a semicolon.
  6. A structure definition is usually placed outside of any function defintion (the same way that globally defined constant declarations are placed outside of all function definitions.
  7. A structure variable can hold values just like any other variable can hold values. A structure value is a collection of smaller values called member values.
  8. Each of these member names can be used to pick out one smaller variable that is a part of the larger structure variable. These smaller variables are called member variables. Member variables are specified by giving the name of the structure variable followed by a dot.
  9. Each data member without an initializer is initialized to a 0 value of an appropiate type for the variable.
  10. Combining a number of items, such as variables and functions, into a single package, such as an object of some class, is called encapsulation.
  11. When a member function is defined, the definition must include the class name because there may be 2 or more classes that have member functions with the same name.
  12. The operator :: is called the scope resolution operator and it serves a purpose similar to that of the dot operator. Both the dot operator and the scope resolution operator are used to tell what a member function is a member of.
  13. The scope resolution operator :: is used with a class name, whereas the dot operator is used with objects with class variables.
    i.e. ClassName::functionName(parameters_list)
  14. The class name that precedes the scope resolution operator is often called a type qualifier because it specializes or qualifies the function name of 1 particular type.
  15. You use the dot operator to specify the member of the object.
    i.e. today.output( );
  16. You use the scope resolution operator to specify the class name when giving the function definition for a member function.
    i.e. void DayOfYear::output( )
  17. Private members are member variable names that cannot be directly accessed in the program except within the definition of a member function.
  18. The variables that follow the label private: will private member variables and the functions that follow it will be private member functions.
  19. When defining a class, the normal practice is to make all member variables private. This means that the member variables can only be accessed or changed using the member functions.
  20. Member functions that allow you to find out the values of the private member variables are called accessor functions.
  21. Member functions that allow you to change the values of the private member variables are called mutator functions. It is important to always include mutator functions with each class definition so that you can change the data stored in an object.
  22. It is perfectly legal to use the assignment operator = with objects or with structures.
  23. Classes have both member variables and member functions.
  24. A member (member variable or member function) may be either public or private.
  25. Normally, all the member variables of a class are labeled as private members.
  26. A private member of a class cannot be used except within the definition of another member function of the same class.
  27. The name of a member function for a class may be overloaded just like the name of an ordinary function.
  28. A class may use another class as the type for a member variable.
  29. A function may have formal parameters whose types are classes.
  30. A function may return an object, that is, a class may be the type for the value returned by a function.
  31. A Constructor is a member function that is automatically called when an object of that class is declared. A constructor is used to initialize the values of member variables and to do any other sort of initialization that may be needed.
  32. A constructor must have the same name as the class and a constructor definition cannot return a value.
  33. Normally, you should make constructors public member functions.
  34. A constructor that can be called with no arguments is called a default constructor since it applies in the default case where you declare an object without specifying any arguments.
  35. Do not include parentheses when you declare an object and want C++ to use the constructor with no arguments.
    i.e. BankAccount account1;