Solved

Referencing a Variable

Posted on 2006-11-20
2
156 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
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

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: 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.
This video discusses moving either the default database or any database to a new volume.

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

12 Experts available now in Live!

Get 1:1 Help Now