Solved

static variable in mfc

Posted on 2001-07-26
3
293 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 51
sum13 challenge 24 90
sumHeights  challenge 17 66
Sed question 2 69
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now