Globals in MFC

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

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::g_MyFunction from any other class...

 



Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • With the cloud transforming application development and deployment — enabling organizations to improve flexibility, automate processes, and decrease time to market — some big questions remain. One of the most important issues an organization must address is how it can best employ the smarter tools and limitless scale that the cloud offers. One way that enterprises take advantage of the benefits of the cloud is by deploying their own private cloud. Read this white paper to learn how private clouds …

  • Chuze Fitness is a fast-growing fitness chain with over 21 locations spanning California, Arizona and Colorado. Chief information and marketing officer, Kris Peterson, explains why access to fast and reliable Wi-Fi is a "must have" service at their gyms and why they switched to Ruckus Cloud Wi-Fi. Chuze Fitness needed to provide a good user experience to the hundreds of guests streaming music, podcasts and videos as they worked out. They also needed to adequately cover their sprawling 20-40,000 square foot …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date