I am having trouble understanding the use of pointers in this program:
#include<iostream.h>
class ABC
{
public:
int data;
void getdata()
{
cout<<"Enter data: ";
cin>>data;
cout<<"The number entered is: "<<data;
}
};
void main()
{
ABC obj;
int *p;
obj.data = 4;
p = &obj.data;
cout<<*p;
ABC *q;
q = &obj.data;
q->getdata();
}
I get everything until the next step: ABC *q;
What does it do? My book says it is a class pointer (it is very vague with pathetic grammar). But what does this mean? Pointer pointing to an ABC class address?
If so, the next step bothers me. q = &obj.data;
Therefore, we point this pointer to the location of the data, which is a variable. How does this ABC *q;fit in then?
And the last step. What does it do q->getdata();? My book says that it is a "pointer to a member operator", but does not provide an explanation.
Glad to get any help!
source
share