August 2001
Beginner
482 pages
10h 52m
English
Static member functions are like static member variables: They exist not in an object but in the scope of the class. Therefore, they can be called without having an object of that class, as illustrated in Listing 20.2.
0: //Listing 20.2 static data members 1: #include <iostream> 2: 3: class Cat 4: { 5: public: 6: Cat(int age = 1):itsAge(age){HowManyCats++; } 7: virtual ~Cat() { HowManyCats--; } 8: virtual int GetAge() { return itsAge; } 9: virtual void SetAge(int age) { itsAge = age; } 10: static int GetHowMany() { return HowManyCats; } 11: private: 12: int itsAge; 13: static int HowManyCats; 14: }; 15: 16: int Cat::HowManyCats = 0; 17: 18: void TelepathicFunction(); 19: 20: int ... |
Read now
Unlock full access