Solved

static variable in mfc

Posted on 2001-07-26
3
303 Views
Last Modified: 2013-11-20
I would like to use a static variable as member data of an class in an mfc dialog based application.Here where should I do forward declaration?

eg:

class dlgMyclass
{
  static int a;
  public:
  void say()
  {
     AfxMessageBox("hi");
   }
};

where to do forward declaration i.e.  int dlgMyclass::a;

Please suggest me the solution for this.
0
Comment
Question by:joshig
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6322104
>>where to do forward declaration i.e.  int dlgMyclass::a;

You don't need a foward declaration, all you have to do is instantiating storage space for the variable:

class dlgMyclass
{
 static int a;
 public:
 void say()
 {
    AfxMessageBox("hi");
  }
};

int dlgMyclass::a = 0;
0
 
LVL 30

Expert Comment

by:Axter
ID: 6323901
FYI,
Adding to jkr comment, you usally want to put the implementation in the *.cpp file.
So
//Put in header (*.h) file
class dlgMyclass
{
static int a;
public:
void say()
{
   AfxMessageBox("hi");
 }
};
/////////////////////////////////

//Put in source (*.cpp) file
int dlgMyclass::a = 0;

0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9490562
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by : jkr

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
method notes when mouse over in eclipse 5 86
while loop over for loop 7 102
noX challenge 17 115
Is there a simple front-end menu system. 9 88
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

775 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