?
Solved

Referencing a Variable

Posted on 2006-11-20
2
Medium Priority
?
166 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 2000 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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

765 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