You are on page 1of 6

Objects and Arrays

OOC
4th Sem, ‘B’ Div
2016-17
Prof. Mouna M. Naravani
Array of Objects
➢ It is possible to create array of objects.
➢ We can have arrays of variables that are of the type class. Such variables are called
arrays of objects.
Ex:
class employee
Creating array of objects:
{
char name[20]; employee manager[3]; // array of manager
float age;
employee worker[75]; // array of worker.
public:
void getdata(); ➢ The array of manager contains three objects,
void putdata();
manager[0], manager[1] and manager[2].
}
Accessing array of objects

manager[i].getdata(); Ex: ArrayOfObj.cpp

manager[i].putdata();

Storage of array of objects

name
manager[0]
age

name
manager[1]
age

name
manager[2]
age
Arrays inside Objects
➢ An array can be declared inside a class.
➢ Such an array becomes a member of all objects of the class.
➢ It can be manipulated/accessed by all member functions of the class.
Ex:
class example
{
int arr[10];
-------
-------
}
References

➢ Sourav Sahay, “Objected Oriented Programming with C++”

➢ E Balagurusamy, “Objected Oriented Programming with C++”

You might also like