Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Variable HELP

Posted on 2000-02-26
2
Medium Priority
?
171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
bbousquet earned 100 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

704 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