Sams Teach Yourself C++ in 21 Days

(singke) #1

Day 15


Quiz


  1. Yes. They are member variables and their access can be controlled like any other.
    If they are private, they can be accessed only by using member functions or, more
    commonly, static member functions.
    2.static int itsStatic;
    3.static int SomeFunction();
    4.long ( function)(int);
    5.long ( Car::
    function)(int);
    6.long ( Car::*function)(int) theArray [10];


Exercises


  1. The following is one possible answer:
    0: // Ex1501.cpp
    1: class myClass
    2: {
    3: public:
    4: myClass();
    5: ~myClass();
    6: private:
    7: int itsMember;
    8: static int itsStatic;
    9: };
    10:
    11: myClass::myClass():
    12: itsMember(1)
    13: {
    14: itsStatic++;
    15: }
    16:
    17: myClass::~myClass()
    18: {
    19: itsStatic--;
    20: }
    21:
    22: int myClass::itsStatic = 0;
    23:
    24: int main()
    25: {
    26: // do something
    27: return 0;
    28: }


850 Appendix D

32 0672327112_app_d.qxd 11/19/04 12:30 PM Page 850

Free download pdf