473,765 Members | 2,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1818
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
2382
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. Two sub-classes have the relationship to communicate back and forth through this pointer. The pointer is responsible inside Top class for allocating and deallocating two sub-classes. CMemory class is responsible to allocate and deallocate memory...
5
8732
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 conceptually speaking : when do I define something as 'struct' and when as 'class' ? for example : if I want to represent a 'Time' thing, containing : - data members : hours, mins, secs
5
1924
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 are held in an xml file to which the com has access. The xml file has different nodes for different instances (dev,uat1,uat2 etc..) there is a flag attribute to show current instance.
12
7311
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". System.Web.HttpContext.Current.Session.Add("myKey", "myValue") Dim a As String a = System.Web.HttpContext.Current.Session.Item("myKey")
9
3688
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? End Sub
8
2745
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 expose the variables or is it OK to just access the variables directly? Keep in mind that I am talking about accessing the variables from within the class that they are defined. Thanks!
7
2116
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 ----------------------------------------------------------------------------- This is a consortium of ideas from another thread on topic ----------------------------------------------------------------------------- One of the big issues of organizing items within a class, is there are many...
5
2334
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 same answer. Web App: - constants.php begin - define("DB_HOST", "locahost"); .... to include the standard connection info define("DB_NAME", "mydatabase");
5
1521
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 Class. It seems to work pretty well. I have the actual data memory variables stored as an object as each class will use it as a different type of object (not sure if this is a problem). The system can tell if the variable is a string, boolean or...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.