100 likes | 108 Views
This text covers key learning objectives in C++ including bitwise operators, register storage class, conditional compilation, separate compilation, exception handling, and namespaces. It provides examples and explanations for each concept.
E N D
Learning Objectives • What else in C++ • Bitwise operator • Register storage class • Conditional compilation • Separate compilation • Exception handling • Namespace
Bitwise Operator • Binary Math • 0 + 0 = 0 • 0 + 1 = 1 • 1 + 1 = 10
Register Storage Class • Example register int Miles; • Variable Miles is stored in register instead of main memory for quick access
Conditional Compilation • You are trying to write a portable program for different compiler, operating system, or computer. • Example (delete file): unlink for Unix, remove for regular C library #ifdef Unix unlink(filename); #else remove(filename); #endif
Conditional Compilation • Then, you could place the line #define Unix • at the top of the file when compiling under an old Unix system
Separate Compilation • Divide one program into different header files and source code files • As we did in homework and project • During compilation, the system will replace #include “xxx.h” with the contents of “xxx.h” • Only compile once: save time • Also support conditional compilation
Exception handling: Standard approach to handle errors void function_F() { Try { <do something> If(error condition) throw exception; <do something> } Catch (MyException e) { <Handle exception>} }
Namespace • A namespace is a collection of name definitions, such class definition, variable declarations, and function definitions #include <iostream> using namespace std; Place all the name definitions (for example, cin, cout) into std name space and use this space
Namespace • With namespace, you can • Redefine the existing names (functions, classes, variables) such as cin, cout • You need to create a new space for them • Assign one name (function, class, variable) with different definitions • You need to create separate spaces for them