Accessing pointer member of a class with an object

class A
{
int *p;
int a;
A()
{
p=&a;
a=10;
}
};
void main()
{
A obj;
//How do i access the pointer p inside the class using the object???
}
You can't, everything in that class is private. You can't even construct an object because the only constructor you gave it is private. If you want data to be public, you need to use the public access modifier.
Last edited on
1
2
3
//I think you have these two line backwards... (Switch them around?)
p=&a;
a=10;
They don't seem backward to me...

EDIT: Oh, I see what you meant, but really the order does not matter.
Last edited on
Topic archived. No new replies allowed.