Introduction to C++ Classes
Classes (also known as composite data types) are a collection of different data types grouped together to form one new self-defined data type which can be categorized in form of a structure, class or union. The variable types we have used so far have been primitive types because they are declared in a very simplified manner. Each variable represented an object in its whole ( i.e int car) but at times we want a group of values to be considered as one entity to represent an object (car).
For example, we may need to use one or more data types to represent the car object. In such a situation we can group the different data types into one data type of our liking and then use it the same way we have used other data types. In C++, there are three techniques of defining a new self-defined data type: a structure, a class, and a union.
For example, we may need to use one or more data types to represent the car object. In such a situation we can group the different data types into one data type of our liking and then use it the same way we have used other data types. In C++, there are three techniques of defining a new self-defined data type: a structure, a class, and a union.
Structures
A structure is an aggregate of data types that together form new self-defined data type. It is built using several types including the structs. We create a structure using a the struct keyword, followed by a name for the object and the body of the structure with a semicolon at the end. The naming of the struct must follow conventional rules of names in C++. To create a composite type at least one known data type should be used to declare a variable in the body of the structure. Below is an example of a car structure.Read more on C++ Classes
No comments:
Post a Comment