The struct keyword is used to create an aggregate data type called a structure. In C++, a structure can contain both function and data members. It has the same capabilities as a class except that, by default, its members are public rather than private. The general form of a C++ structure is

 struct class-name : inheritance-list {     // public members by default  protected:     // private members that can be inherited private:     // private members } object-list; 

The class-name is the type name of the structure, which is a class type. The individual members are referenced using the dot operator when acting on an object or by using the arrow operator when acting through a pointer to the object. The object-list and inheritance-list are optional.

In C, structures must contain only data members, the private, public, and protected specifiers are not allowed, and no inheritance list is allowed.

The following C-style structure contains a string called name and two integers called high and low. It also declares one variable called my_var.

struct my_struct {   char name[80];   int high;   int low; } my_var;

Chapter 1 covers structures in more detail.

C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539

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