This has been bugging me since v1.0 or so :P
1) Create a new MFC project "SingletonProblem" (dialog-based).
2) Add these lines in SingletonProblem.h:
class CSingleton
{
};
And a public function in CSingletonApp:
friend CSingleton& GetSingleton();
Then, in SingletonProblem.cpp, add the implementation:
CSingleton& GetSingleton()
{
static CSingleton singleton;
return singleton;
}
3) Go to CSingletonProblemDlg::OnInitDialog() and add:
GetSingleton();
VAX 1649 (and no previous version?) will not recognize that function call! It gets underlined and adding a "." makes the programmer go nuts... :)
This type of "elegant" singleton declarations are very common in our projects. Please fix this!