13.8 Structures Versus Classes

I l @ ve RuBoard

In C++ a structure is just like a class, except that all the data fields and member functions are public. For example, the following two are the same:

 struct data {     int status;     int data;     void start(  ) {         status = 1;     } }; 
 public data {     public:         int status;         int data;         void start(  ) {             status = 1;         } }; 

As you can see, a structure is merely a class with all the protections removed. This means that in most cases a class is superior to a structure.

In actual practice, most programmers use structures for data only. You'll hardly ever see a structure with member functions.

I l @ ve RuBoard


Practical C++ Programming
Practical C Programming, 3rd Edition
ISBN: 1565923065
EAN: 2147483647
Year: 2003
Pages: 364

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net