cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
user name:
password:
Forgot your password?
please wait
try again
cancel
forgot your password?
sign up
log in
[Legacy version]
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Accessing pointer member of a class with
Accessing pointer member of a class with an object
Jun 19, 2011 at 5:53am
Jun 19, 2011 at 5:53am UTC
mohnishkhiani
(1)
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
Jun 19, 2011 at 5:56am UTC
LB
(13399)
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 5:57am UTC
Jun 19, 2011 at 12:15pm
Jun 19, 2011 at 12:15pm UTC
Mathhead200
(1016)
1
2
3
//I think you have these two line backwards... (Switch them around?)
p=&a; a=10;
Jun 19, 2011 at 3:55pm
Jun 19, 2011 at 3:55pm UTC
LB
(13399)
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
Jun 19, 2011 at 3:56pm UTC
Topic archived. No new replies allowed.