Sams Teach Yourself C++ in 21 Days
If you create a program that uses both a Catand a Dog, you will be in danger of includ- ing ANIMAL.hpptwice. This generates a co ...
What’s Next 757 21 The entire string TWICE(4)is removed, and the value ( (4) 2 )is substituted. When the precompiler sees the 4 ...
and pass in the values 5 and 7 , the macro works as intended. But, if you pass in a more complicated expression, you receive uni ...
What’s Next 759 21 which evaluates to ( (12) * (12) * (12) ) which, in turn, evaluates to 1728. THREE(5+7), however, evaluates t ...
Assume for a moment that you have five functions named fOnePrint,fTwoPrint, fThreePrint,fFourPrint, and fFivePrint. You can then ...
What’s Next 761 21 precompiled, not when the program is run. If you ask the program to print __DATE__, you do not get the curren ...
22: cout << “\nSecond assert: “ << endl; 23: ASSERT(x != 5); 24: cout << “\nDone. << endl”; 25: return 0 ...
What’s Next 763 21 Using assert()Versus Exceptions ................................................................ Yesterday, y ...
When you pass the assert()statement,xreally is equal to 5 (you just set it!). Your pro- gram runs just fine. You’re ready to shi ...
What’s Next 765 21 21: typedef int BOOL; 22: 23: 24: class String 25: { 26: public: 27: // constructors 28: String(); 29: String ...
69: // Converts a character array to a String 70: String::String(const char * const cString) 71: { 72: itsLen = strlen(cString); ...
What’s Next 767 21 117: char & String::operator[](int offset) 118: { 119: ASSERT(Invariants()); 120: if (offset > itsLen) ...
165: ASSERT(Invariants()); 166: } 167: String& GetName() 168: { 169: ASSERT(Invariants()); 170: return itsName; 171: } 172: ...
What’s Next 769 21 String Tested OK String Tested OK String Tested OK String Tested OK String Tested OK String Tested OK String ...
7: #else 8: #define PRINT(x) \ 9: cout << #x << “:\t” << x << endl; 10: #endif 11: 12: enum BOOL { FALSE ...
What’s Next 771 21 Macros Versus Functions and Templates Macros suffer from four problems in C++. The first is that they can be ...
16: cout << “. Square(“ << x << “): “; 17: cout << Square(x); 18: cout<< “. Cube(“ << x < ...
What’s Next 773 21 Bit Twiddling ............................................................................................... ...
Operator OR .................................................................................................. The second bitwis ...
What’s Next 775 21 set every bit that is clear, and clear every bit that is set (0111 1111). When you AND these numbers, the ori ...
«
35
36
37
38
39
40
41
42
43
44
»
Free download pdf