Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

static variable in mfc

Posted on 2001-07-26
3
Medium Priority
?
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

704 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