Solved

static variable in mfc

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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

23 Experts available now in Live!

Get 1:1 Help Now