How to Create Multiple Objects for a class In C++
We do not manipulate the data directly. We can do so only by using
functions and objectsImagine you want to build an application to keep track of all the books. The data has to be considered in
OOP Here, our data is all about books. Therefore, the first object type is a book.
Now, we have designed the object in such a way that all the data can be stored in a state for any further manipulation. In C++, the design of an object is done by creating a class. For programmers, a class is similar to
(a blueprint of a building) to an architect.
In case, if you give those books to others then, the person also becomes an object. Therefore, you create a person class. The tracking app can then create a
new object of a person class and fill it with data about your friend.
C++ Program to Create Multiple Objects for a class
Enter any integer value 456
Enter any integer value 789
The value is :234
The value is :456
The value is :789
Explanation of the program
In this program, the
print() member functions are shared by all the objects of the type sample. Whereas in the case of data members, each object i.e.
s1, s2, and s3 has its own copy.
© 2016-2019, Codeverb.com - All Rights Reserved