[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Referencing a Variable

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

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

834 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