Click here to Skip to main content
15,888,208 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Static class members Pin
Richard MacCutchan15-May-11 7:13
mveRichard MacCutchan15-May-11 7:13 
GeneralRe: Static class members Pin
csrss16-May-11 5:43
csrss16-May-11 5:43 
AnswerRe: Static class members Pin
Niklas L16-May-11 0:42
Niklas L16-May-11 0:42 
GeneralRe: Static class members Pin
csrss16-May-11 5:46
csrss16-May-11 5:46 
GeneralRe: Static class members Pin
Stefan_Lang17-May-11 0:48
Stefan_Lang17-May-11 0:48 
GeneralRe: Static class members Pin
csrss17-May-11 5:38
csrss17-May-11 5:38 
GeneralRe: Static class members Pin
Stefan_Lang17-May-11 6:18
Stefan_Lang17-May-11 6:18 
AnswerRe: Static class members Pin
Stefan_Lang16-May-11 3:03
Stefan_Lang16-May-11 3:03 
csrss wrote:
so i can use it in some static methods

If you want to use static member functions or access static variables in your class, you do not have to use a static pointer or instance of that class!

When a member function is static, it means that it does not access any data members of the class or its base class(es), and also it does not use any member function that isn't also static. Therefore you do not need an instance of the class at all!

Here is an example:
class CMyClass {
private:
   static int myMagicNumber;   // defined static member variable here
public:
   static void magic() {       // defined a static method here
      std::cout << "My magic number is: " << myMagicNumber << std::endl;
   }
};

// initialize the static member variable in one of your cpp files like this:
CMyClass::myMagicNumber = 111;

int main() {
   // call your static method like this:
   CMyClass::magic(); // prints "My magic number is: 111"
}

As you can see I never created an instance anywhere; it isn't needed.
GeneralRe: Static class members Pin
csrss16-May-11 5:52
csrss16-May-11 5:52 
GeneralRe: Static class members [modified] Pin
Stefan_Lang16-May-11 6:11
Stefan_Lang16-May-11 6:11 
QuestionCreating a window without focus [modified] Pin
csrss15-May-11 2:25
csrss15-May-11 2:25 
AnswerRe: Creating a window without focus Pin
Luc Pattyn15-May-11 2:45
sitebuilderLuc Pattyn15-May-11 2:45 
GeneralRe: Creating a window without focus Pin
csrss15-May-11 2:50
csrss15-May-11 2:50 
AnswerRe: Creating a window without focus Pin
Alain Rist15-May-11 3:43
Alain Rist15-May-11 3:43 
GeneralRe: Creating a window without focus Pin
csrss15-May-11 4:57
csrss15-May-11 4:57 
QuestionHow to get the keyboard event? Pin
sharanu14-May-11 23:06
sharanu14-May-11 23:06 
AnswerRe: How to get the keyboard event? Pin
«_Superman_»15-May-11 2:00
professional«_Superman_»15-May-11 2:00 
AnswerRe: How to get the keyboard event? Pin
Mark Salsbery15-May-11 8:39
Mark Salsbery15-May-11 8:39 
QuestionEdit Text Pin
john563214-May-11 22:46
john563214-May-11 22:46 
AnswerRe: Edit Text Pin
Mark Salsbery14-May-11 22:58
Mark Salsbery14-May-11 22:58 
AnswerRe: Edit Text Pin
Hans Dietrich14-May-11 23:08
mentorHans Dietrich14-May-11 23:08 
AnswerRe: Edit Text Pin
Alain Rist14-May-11 23:15
Alain Rist14-May-11 23:15 
QuestionLButtonDown Event on Button Pin
sharanu14-May-11 22:00
sharanu14-May-11 22:00 
AnswerRe: LButtonDown Event on Button Pin
Hans Dietrich14-May-11 22:53
mentorHans Dietrich14-May-11 22:53 
Questionadd menu item Pin
john563214-May-11 16:05
john563214-May-11 16:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.