Solved

Variable HELP

Posted on 2000-02-26
2
164 Views
Last Modified: 2013-11-20
Hi,

 If I have a variable in a class,
 how can I get the value of this variable in another class ?
0
Comment
Question by:RogerioSilva
2 Comments
 
LVL 2

Accepted Solution

by:
bbousquet earned 50 total points
ID: 2561245
You have a number of choices for doing that:

1. If your 2nd class knows an instance of the 1st one, make the variable public

2. If your 2nd class knows only the structure of the 1st class, you can make the variable static

3. If your 2nd class knows an instance of the 1st one, but the variable is private/protected, you can always make the two classes friends (which I don't really recommend)

4. If your 2nd class knows an instance of the 1st one, you can add a public method to the 1st class which returns the value of the variable.

5. If your 2nd class derives from the 1st class, and the variable is protected, you can access it transparently.

Take your pick!
0
 
LVL 1

Author Comment

by:RogerioSilva
ID: 2561249
thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now