C++ Chapter 12: Separate Compilation & Namespaces

Card Set Information

Author:
senator77
ID:
147601
Filename:
C++ Chapter 12: Separate Compilation & Namespaces
Updated:
2012-04-15 15:21:07
Tags:
separate compilation namespaces
Folders:

Description:
C++ Chapter 12: Separate Compilation & Namespaces
Show Answers:

Home > Flashcards > Print Preview

The flashcards below were created by user senator77 on FreezingBlue Flashcards. What would you like to do?


  1. Namespaces are a way of allowing you to reuse the names of classes, functions, and other items by qualifying the names to indicate different uses.
  2. Namespaces divide your code into sections so that the different sections may reuse the same names with different meanings.
  3. Namespaces allow a kind of local meaning for names that is more general than local variables.
  4. An ADT (abstract data type) is a class that has been defined so as to separate the interface and the implementation of the class.
  5. In an ADT make all the member variables private members of the class.
  6. In an ADT make each of the basic operations for the ADT (the class) either a public member function of the class, a friend function, an ordinary function, or an overloaded operator. Group the class definition and the function and operator declarations together. This group, is called the interface for the ADT. Fully specify how to use each such function or operator in a comment given with the class or with the function or operator declaration.
  7. In an ADT make the implementation of the basic operations unavailable to the programmer who uses the ADT. The implementation consists of the function definitions and overloaded operator definitions (along with any helping functions or other additional items these definitions require).
  8. An interface file ia always a header file and therefore always ends with the suffix .h.
  9. When you wirte an include directive, you must indicate whether the header file is a predefined header file that is provided for you or is a header file that you wrote. If its predefined, write the header file name in angular brackets, <iostream>. If its one you wrote, write the header file name in quotes, "fileName.h". This tells the compiler where to look for the header file.
  10. The file that contains the program (the file that contains the main part of the program) is often called the application file or driver file.
  11. A namespace is a collection of name definitions, such as class definitions and variable declarations.
  12. Every bit of code that you write is in some namespace. If you do not place the code in some specific namespace, then the code is in a namespace known as the global namespace.
  13. The scope of a using directive is the block in which it appears (more precisely, from the location of the using directives to the end of the block). If the using directive is outside of all blocks, then it applies to all of the file that follows the using directive.
  14. A using declaration of the form:
    using nameSpace::oneName
    makes (the definition of) the name oneName from the namespace nameSpace available, but does not make any other names in nameSpace available.
  15. A using directive (like using std::cout;) makes only one name in the namespace available to your code, while a using directive (like using namespace std;) makes all the names in a namespace available.
  16. A using declaration introduces a name (like cout) into your code so that no other use of the name can be made. However, a using directive only potentially introduces the names in the namespace.
  17. A compilation unit is a file, such as a class implementation file, along with all the files that are #included in the file, such as the interface header file for the class.
  18. Every compilation unit has an unnamed namespace. A namespace grouping for the unnamed namespace is written in the same way as any other namespace, but no name is given.
    i.e.:
    namespace
    {
    void sampleFunction( )
    .....
    .....
    } // unnamed namespace
  19. All the names defined in the unnamed namespace are local ot the compilation unit, and thus the names can be reused for something else outside the compilation unit.
  20. It is a good idea to include your last name or some other unique string in the names of your namespaces so as to reduce the chance that somebody else will use the same namespace name as you do. With multiple programmers writing code for the same project, it is important that namespaces that are meant to be distinct really do hvae distinct names.
  21. In C++, ADTs are implemented as classes with all member variables private and with the operations implemented as public member and nonmember functions and overloaded operators.
  22. You can define an ADT as a class and place the definition of the class and the implementation of its member functions in separate files. You can then compile the ADT class separately from any program that uses it and you can use this same ADT class in any number of different programs.
  23. There are 3 ways to use a name from a namespace:
    1. make all the names in the namespace available with a using directive.
    2. make the single name available by a using declaration for the one name.
    3. qualifying the name with the name of the namespace and the scope resolution operator.
  24. You place a definition in a namespace by placing it in a namespace grouping for that namespace.
  25. The unnamed namespace can be used to make a name definition local to a compilation unit.
  26. Namespaces should be considered when moving the class definitions, implementation, and application into separate files.

What would you like to do?

Home > Flashcards > Print Preview