468,458 Members | 1,745 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,458 developers. It's quick & easy.

class access to variables

cdg
Is there any way to directly access variables of one class from another
class without passing any public member variables. Similar to how any
function in a class can directly access (without passing an argument) any
member variable of its' own class.
I thought the only way this could be possible would be to make a function
a "friend" of the class. But I now beleive that it is still necessary to
pass variables to the other class, is this true.
Jul 6 '06 #1
2 1584
cdg wrote:
Is there any way to directly access variables of one class from
another class without passing any public member variables. Similar to
how any function in a class can directly access (without passing an
argument) any member variable of its' own class.
Sure. Make them public or declare the class that needs the access
a friend of the other class.
I thought the only way this could be possible would be to make a
function a "friend" of the class. But I now beleive that it is still
necessary to pass variables to the other class, is this true.
No, it is not true. All you need is to declare something a friend.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 6 '06 #2

cdg wrote:
Is there any way to directly access variables of one class from another
class without passing any public member variables. Similar to how any
function in a class can directly access (without passing an argument) any
member variable of its' own class.
I thought the only way this could be possible would be to make a function
a "friend" of the class. But I now beleive that it is still necessary to
pass variables to the other class, is this true.
Do you mean private variables? Your explanation is a bit vague.

A few options:

1. Make the variables public.

2. Use public accessor methods that return or modify the values of
private class attributes

3. Make the other *class* a friend of the class that contains the
private variables you want to access.

Jul 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Bryan Parkoff | last post: by
5 posts views Thread by adolf garlic | last post: by
12 posts views Thread by Thomas Andersson | last post: by
5 posts views Thread by Slant | last post: by
5 posts views Thread by tshad | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.