Professional Documents
Culture Documents
01 Structs
01 Structs
01 Structs
STRUCTS
1. Brief review of key concepts and terminology of object-oriented programming:
2. OOP encapsulates data (attributes) and functions (behaviors) into packages called
objects; the data and functions of an object are intimately tied together.
1. Structures are aggregate data types built using things of other types.
a) Example of a structure definition:
struct Time {
int hour;
int minute;
int second;
};
Time timeObject;
...
cout << timeObject.hour;
ii) The arrow operator (->), consisting of a minus (-) sign followed by a
greater than (>) sign with no intervening spaces, accesses a structure (or
class) member via a pointer to the object.
a) To print member hour of structure timeObject with pointer timePtr:
Time timeObject;
Time *timePtr = &timeObject;
...
cout << timePtr->hour;
main()
{
Time dinnerTime; // variable of new type Time
Output is: