Click here to Skip to main content
15,890,512 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Multiple includes Pin
Shy Agam30-Aug-10 23:50
Shy Agam30-Aug-10 23:50 
GeneralRe: Multiple includes Pin
Aescleal31-Aug-10 0:30
Aescleal31-Aug-10 0:30 
GeneralRe: Multiple includes Pin
Tim Craig31-Aug-10 8:59
Tim Craig31-Aug-10 8:59 
GeneralRe: Multiple includes Pin
Aescleal31-Aug-10 9:13
Aescleal31-Aug-10 9:13 
GeneralRe: Multiple includes Pin
Paul Michalik31-Aug-10 12:35
Paul Michalik31-Aug-10 12:35 
GeneralRe: Multiple includes Pin
Tim Craig31-Aug-10 13:12
Tim Craig31-Aug-10 13:12 
GeneralRe: Multiple includes Pin
Paul Michalik31-Aug-10 21:29
Paul Michalik31-Aug-10 21:29 
GeneralRe: Multiple includes [modified] Pin
Paul Michalik31-Aug-10 6:28
Paul Michalik31-Aug-10 6:28 
No! You may declare your static class members only once. What you have missed, is the definition (which also has to be unique), and it needs to be provided outside of the class, for non-const and non-trivial objects.

// in AStuff.h
class AStuff {
public:
 void Hello() {
  // ...
 }
};

// in A.h
class A {
public:
 static AStuff sStaticAMember; // <-declaration
};

// in A.cpp
AStuff A::sStaticAMember; //<-definition (required!)


The constructor for A::sStaticAMember will be called by the runtime (dynamic initialization) if the instance is used by the program. You do not (really) have the control over when this is going to happen, neither when the destructor is going to be called. This is one of the reason why the poster above damned "statics" ... and basically I have to agree with him.

Are you using C# otherwise? If yes, then forget about the comfort of static class objects and their well defined initialization there - and enter one of the many dark zones of c++. I assume you will probably run into the problem of undefined order of initializations of your non-local objects, but we stand ready to help Smile | :)

modified on Tuesday, August 31, 2010 12:56 PM

GeneralRe: Multiple includes Pin
Shy Agam31-Aug-10 21:27
Shy Agam31-Aug-10 21:27 
GeneralRe: Multiple includes Pin
Paul Michalik31-Aug-10 23:57
Paul Michalik31-Aug-10 23:57 
GeneralRe: Multiple includes Pin
Shy Agam1-Sep-10 2:13
Shy Agam1-Sep-10 2:13 
QuestionIs there any difference in drawing emf on CDC and Bitmap? Pin
Sameerkumar Namdeo29-Aug-10 21:46
Sameerkumar Namdeo29-Aug-10 21:46 
Questionhow to find memory leaks in attached dll Pin
ganesh.dp29-Aug-10 20:02
ganesh.dp29-Aug-10 20:02 
AnswerRe: how to find memory leaks in attached dll Pin
Eugen Podsypalnikov29-Aug-10 20:18
Eugen Podsypalnikov29-Aug-10 20:18 
AnswerRe: how to find memory leaks in attached dll PinPopular
Niklas L29-Aug-10 20:41
Niklas L29-Aug-10 20:41 
AnswerRe: how to find memory leaks in attached dll Pin
ThatsAlok29-Aug-10 20:54
ThatsAlok29-Aug-10 20:54 
AnswerRe: how to find memory leaks in attached dll Pin
rp_suman30-Aug-10 4:14
rp_suman30-Aug-10 4:14 
QuestionBlackBerry IMEI Number Pin
MsmVc29-Aug-10 18:55
MsmVc29-Aug-10 18:55 
AnswerRe: BlackBerry IMEI Number Pin
ThatsAlok29-Aug-10 23:19
ThatsAlok29-Aug-10 23:19 
GeneralRe: BlackBerry IMEI Number Pin
MsmVc29-Aug-10 23:21
MsmVc29-Aug-10 23:21 
GeneralRe: BlackBerry IMEI Number Pin
sayonee30-Aug-10 1:30
sayonee30-Aug-10 1:30 
GeneralRe: BlackBerry IMEI Number Pin
MsmVc30-Aug-10 1:34
MsmVc30-Aug-10 1:34 
GeneralRe: BlackBerry IMEI Number Pin
enhzflep30-Aug-10 16:24
enhzflep30-Aug-10 16:24 
QuestionHooking OleGetClipboard Pin
Member 382162029-Aug-10 10:28
Member 382162029-Aug-10 10:28 
AnswerRe: Hooking OleGetClipboard Pin
Code-o-mat29-Aug-10 22:12
Code-o-mat29-Aug-10 22:12 

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.