Solved

Global Variable

Posted on 1998-09-06
2
198 Views
Last Modified: 2013-11-20
Can I delcare a global variable in Viusal C++ 5.0?

I want to have a variable that can be used by two *.cpp files.
eg.
I used the class CListView to display all data in the
Window. After clicking one of the items, I want the value
of this itemc can be displayed on the dialog box.
Until now, I cannot do this in using two *.cpp files.

Thanks for your help!!!
0
Comment
Question by:cplau
2 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 20 total points
ID: 1321808
Yes, you can.

For example,

// 1.h
extern int g_nVal;  // declaration

// 1.cpp
#include "1.h"

int g_nVal = 1;  // definition

// 2.cpp
#include "1.h"

g_nVal = 2;  // reference


Another way is to define it as a member variable of the derived CWinApp class.

class CMyWinApp : public CWinApp
{
//...
    public:
        int m_nVal;
//...
};

((CMyWinApp *)::AfxGetApp())->m_nVal = 2;

0
 

Author Comment

by:cplau
ID: 1321809
very helpful
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 66
Hibernate methods 2 58
Doc'in system (example?) BA 7 78
NotAlone Challenge 20 70
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

15 Experts available now in Live!

Get 1:1 Help Now