12.12 POINTERS TO USER DEFINED DATA TYPES
Earlier, we have seen pointers to basic data types. Pointers work exactly in same manner with user-defined data types like structures and objects. We have seen pointers pointing to structures in Chapter 3 “Moving from C to C++”. Let us see how the pointer works with objects.
Consider that we have defined a class “Student”.
class Student { public: int rollNum; char name[40]; Student(); void show()) ;} ;
We can create an object of this class as shown below:
Student someName = new Student ;
Later we can handle data members and methods by using an arrow operator, i.e.,
someName->rollNum or
someName->show()
12.12.1 Array of pointers (to objects)
When we want an array of large number of ...
Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.