May 2012
Intermediate to advanced
679 pages
16h 56m
English
So far, we have studied classes and objects; we have not used pointers with the created object. It is perfectly normal for a pointer to point to an object. Assume that we have defined class Date. Consider the following declarations.
Date d1;
Date *datePointer = & d1;
Here we have defined an object of class Date. We have also declared a pointer to class Date. Then we have made pointer to point to object d1.
Now we can access members of d1 as
(*datePointer).month
If you remember, pointer to structure, you will conclude that there is better way of referring a member for example.
datePointer->month
So far so good. Well if we just want to work with pointers and objects, there is one more way. We can use a new operator ...
Read now
Unlock full access