Array of Objects in C++
Array of Objects in C++
Raj Kumar
Array
An array in C/C++ or be it in any programming
language is a collection of similar data items
stored at contiguous memory locations and
elements can be accessed randomly using indices
of an array.
They can be used to store the collection of
primitive data types such as int, float, double,
char, etc of any particular type.
To add to it, an array in C/C++ can store derived
data types such as structures, pointers, etc.
Array
Array of Objects
Like array of other user-defined data types, an
array of type class can also be created.
The array of type class contains the objects of
the class as its individual elements.
Thus, an array of a class type is also known as
an array of objects.
An array of objects is declared in the same way
as an array of any built-in data type.
Array of Objects
When a class is defined, only the specification for the
object is defined; no memory or storage is allocated.
To use the data and access functions defined in the
class, you need to create objects.
emp[i].getdata();