Solved

Variable HELP

Posted on 2000-02-26
2
168 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maxBlock challenge 30 142
sum13 challenge 24 123
Change to event 1 119
"Black Box" Testing of Control System Software 2 72
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

820 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