Accessing pointer member of a class with an object

Jun 19, 2011 at 5:53am
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???
}
Jun 19, 2011 at 5:56am
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 Jun 19, 2011 at 5:57am
Jun 19, 2011 at 12:15pm
1
2
3
//I think you have these two line backwards... (Switch them around?)
p=&a;
a=10;
Jun 19, 2011 at 3:55pm
They don't seem backward to me...

EDIT: Oh, I see what you meant, but really the order does not matter.
Last edited on Jun 19, 2011 at 3:56pm
Topic archived. No new replies allowed.