Solved

mfc static classes

Posted on 2004-09-22
5
253 Views
Last Modified: 2013-11-20
Hi all,
 

are all mfc classes(in the hiearchy chart provided by microsoft) STATIC in a wizard generated application???

p
0
Comment
Question by:struggling_coder_3203
[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
  • 2
  • 2
5 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 12130522
What do you mean by a class being static?

Functions that are defined with a keyword static can be used by the following technique
int x = CMyClass::MyFnReturnSomeInt();

else you need
CMyClass ob;
int x = ob.MyFnReturnSomeInt();
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12133053
I guess you are not utlizing correctly the term "static", could you explain with more detail what you want to know?
0
 

Author Comment

by:struggling_coder_3203
ID: 12136661
well, i mean, in order to used a classes functionality without instantiating an object of that class, the class must be defined as static. So, if I need to used some kind of functionality in an mfc class, I won't have to instantiate it if it is static.

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12136779
You don't have to instantiate a class as static, but you can use STATIC member (data and functions). If class doesn't have static members you can't use it without instantiating an object.
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 300 total points
ID: 12140411
To repeat my first post

Functions that are defined with a keyword static can be used by the following technique
int x = CMyClass::MyFnReturnSomeInt();

else you need
CMyClass ob;
int x = ob.MyFnReturnSomeInt();

and I posted this in response to your previous question about static functions

Functions can be defined as static and, by default, non-static.
Roughly a static function does not require any initialisation that would be performed in the constructor of the class.  This allows one to call a static function of a class without it being instantated.
Give it a try - create a new class yourself and do something like in the header
static int MyStaticFn() {return 2;};
now in your prog do
int x = CMyTestClass::MyStaticFn();
x now has the value 2.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Macro to save highlighted rows as a separate file 5 51
unix example issues 18 114
how to split multiple lines delimiter : 8 133
Message not shown 5 105
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 …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

751 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