Solved

Referencing a Variable

Posted on 2006-11-20
2
160 Views
Last Modified: 2013-11-20
Hi guys,

This is the situation...

I have: CustomBrowserDlg.cpp, which has this variable:

string ROOT;


I also have: File.h

which needs to be able to read the value of this variable.


What is the best to do? Move the variable to the File.h, and then #include the File.h to CustomBrowserDlg.cpp even though it's not really required inside that file, or what would you guys recommend?


Cheers!
0
Comment
Question by:Cyber-Drugs
[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 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 17980729
Depends.

You can have the variable as a public member of a class and get it through a pointer to an object of that class.

eg

CMyDlg...
{
public:
  string ROOT;
....
}

CMyDlg dlg;
string AnotherString = dlg.ROOT;


If it is to be 'shared' between lots of objects then it might be appropriate to be a member variable of the app
string AnotherString = ((CMyApp*)AfxGetApp())->ROOT;


Just having it as a global variable is against the OOP philosophy.
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 17980994
I'm going to go for the Class Method, cheers! :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
post4 challenge 28 113
mapAB Challlenge 35 174
Problem to event 3 113
unix example issues 18 106
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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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