Solved

Referencing a Variable

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

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

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: 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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

695 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