Globals in MFC

WEBINAR:
Live

Full Text Search: The Key to Better Natural Language Queries for NoSQL in Node.js


Date: 1/31/2018 @ 2 p.m. ET

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

  • Using Internet of Things (IoT) technologies, colleges and universities are linking anything and everything to create new applications that elevate the campus experience. It's called a Smart Campus. And it's transforming campus life for students, faculty and visitors. When everything is connected, devices and applications can interact with users and with each other in ways that weren't possible before: digital classrooms, connected campus ID cards, connected lighting and building environmental systems and …

  • When it comes to storage, not all data is the same. Different data has very different performance and capacity requirements. With the explosion of unstructured data – 80% of data growth worldwide is unstructured data – the landscape has become even more complicated. Make sure you have what you need to handle all this data and store it appropriately. This brief, "Top 5 Reasons to Consider Veritas Access," describes how to manage your data, so it's easily accessible regardless of where it resides …

Most Popular Programming Stories

More for Developers

RSS Feeds

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