turk_bayr.jpg (8863 bytes)

header.jpg (23201 bytes)

PROG
RAM

22 Haz 2001 GLOBALS in MFC

VC++ Articels


button_programming.jpg (4736 bytes)







MFC class framework makes possible to work easily with global variables and functions. Let's declare a static member variable or function in the CWinApp derived class. It is accessible from all classes.

Example:

// MyApp.h
class CMyApp : public CWinApp
{
public:
  CMyApp();
  static int g_nMyVariable;      // declaration
  static void g_MyFunction();    // declaration
  ...
  etc
  ...
};
// MyApp.cpp
int CMyApp::g_nMyVariable = NULL; // definition & initialization
void CMyApp::g_MyFunction()      // definition
{
}

Now the variable and the function are accessible through the syntax CMyApp::g_nMyVariable or CMyApp::gMyFunction from any other class.

home | about me | links | projects | clean energy | programming

 

 

 

 

 

 

Hosted by www.Geocities.ws

1