472,993 Members | 2,049 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.

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 1778
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes....
5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
5
by: adolf garlic | last post by:
Suggestions please for strategy to share values across app. Scenario: I have an asp.net app that uses some com components along with .net classes. Configuration settings for various things...
12
by: Thomas Andersson | last post by:
Hi, How can I access a session variable within a Public Class? I have tried the below code, but I get a server error "Object reference not set to an instance of an object". ...
9
by: Joel Moore | last post by:
I'm a little confused here. If I have the following: Public ClassA Friend varA As Integer Private varB As Integer Private ClassB Public Sub MethodA() ' How can I access varA and varB here?...
8
by: dwok | last post by:
I have been wondering this for a while now. Suppose I have a class that contains some private member variables. How should I access the variables throughout the class? Should I use properties that...
7
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
5
by: Slant | last post by:
Here's a question that most will have different answers to. I'm just dying to find a solution that seems halfway automated!! There really are two seperate issues which might be answered by the...
5
by: tshad | last post by:
In VS 2003, I am setting up an abstract class that is setting up classes for each datatype of VB.Net (as well as C#). I am trying to set it up so that most of the work is done in the Abstract...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.