Sams Teach Yourself C++ in 21 Days
55: 56: tmp = rX; 57: rX *= rX; 58: rX = rX * tmp; 59: 60: tmp = rY; 61: rY *= rY; 62: rY = rY * tmp; 63: } 64: 65: void Swap(in ...
Special Classes and Functions 517 15 functions can be pointed to by pFunc. The user is repeatedly offered the choice of which fu ...
LISTING15.6 Rewriting Listing 15.5 Without the Pointer to Function 0: // Listing 15.6 Without function pointers 1: 2: #include & ...
Special Classes and Functions 519 47: fQuit = true;^15 48: break; 49: } 50: } 51: return 0; 52: } 53: 54: void PrintVals(int x, ...
(0)Quit (1)Change Values (2)Square (3)Cube (4)Swap: 1 x: 1 y: 2 New value for ValOne: 2 New value for ValTwo: 3 (0)Quit (1)Chang ...
Special Classes and Functions 521 15 Arrays of Pointers to Functions............................................................ ...
41: } 42: 43: void PrintVals(int x, int y) 44: { 45: cout << “x: “ << x << “ y: “ << y << endl; 46 ...
Special Classes and Functions 523 15 x: 2 y: 3 x: 4 y: 9 x: 64 y: 729 x: 729 y: 64 x: 531441 y:4096 On line 17, the array pFuncA ...
23: switch (choice) 24: { 25: case 1: pFunc = GetVals; break; 26: case 2: pFunc = Square; break; 27: case 3: pFunc = Cube; break ...
Special Classes and Functions 525 73: void GetVals (int & rValOne, int & rValTwo)^15 74: { 75: cout << “New value ...
LISTING15.9 Using typedefto Make Pointers to Functions More Readable 0: // Listing 15.9. 1: // Using typedef to make pointers to ...
Special Classes and Functions 527 49: rX *= rX;^15 50: rY *= rY; 51: } 52: 53: void Cube (int & rX, int & rY) 54: { 55: ...
On line 10,typedefis used to declare VPFto be of the type “pointer to function that returns voidand takes two parameters, both i ...
Special Classes and Functions 529 13: int itsAge;^15 14: }; 15: 16: class Dog : public Mammal 17: { 18: public: 19: void Speak() ...
62: cin >> Method; 63: switch (Method) 64: { 65: case 1: pFunc = Mammal::Speak; break; 66: default: pFunc = Mammal::Move; ...
Special Classes and Functions 531 15 Arrays of Pointers to Member Functions .................................................... ...
40: { 41: fQuit = true; 42: } 43: else 44: { 45: pDog = new Dog; 46: (pDog->*DogFunctions[Method-1])(); 47: delete pDog; 48: ...
Special Classes and Functions 533 15 Summary ................................................................................... ...
type, however, and the restricted access and strong typing makes static data safer than global data. Q Why use static member fun ...
Special Classes and Functions 535 15 Using the program from Exercise 1, write a short driver program that makes three objects a ...
«
23
24
25
26
27
28
29
30
31
32
»
Free download pdf