Click here to Skip to main content
15,910,661 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: What menu item was selected? Pin
V.4-Aug-04 1:07
professionalV.4-Aug-04 1:07 
AnswerRe: What menu item was selected? Pin
cmk4-Aug-04 9:53
cmk4-Aug-04 9:53 
GeneralRe: What menu item was selected? Pin
gokings5-Aug-04 22:12
gokings5-Aug-04 22:12 
GeneralUrgent:malloc gives access violation for a C dll Pin
rana743-Aug-04 21:07
rana743-Aug-04 21:07 
QuestionHow to use MFC structure CMemory State in a Non-MFC application Pin
Prathima Prabhakar Rao3-Aug-04 20:51
Prathima Prabhakar Rao3-Aug-04 20:51 
AnswerRe: How to use MFC structure CMemory State in a Non-MFC application Pin
Anthony_Yio4-Aug-04 1:19
Anthony_Yio4-Aug-04 1:19 
QuestionHow to draw figures in MSFlexgrid Cell Pin
kjadhav3-Aug-04 20:18
kjadhav3-Aug-04 20:18 
Questiondebug mode fails to run?? Pin
xxhimanshu3-Aug-04 19:47
xxhimanshu3-Aug-04 19:47 
AnswerRe: debug mode fails to run?? Pin
Milton Karimbekallil3-Aug-04 20:23
Milton Karimbekallil3-Aug-04 20:23 
Generalsystem log-off/shut-down response from my application Pin
Anonymous3-Aug-04 19:20
Anonymous3-Aug-04 19:20 
GeneralPlease help me with the Arithmetic Coding base on Khalid Sayood Pin
huffmancoding3-Aug-04 18:48
huffmancoding3-Aug-04 18:48 
Generalstarting an application at startup, before logging in Pin
Anonymous3-Aug-04 18:22
Anonymous3-Aug-04 18:22 
GeneralRe: starting an application at startup, before logging in Pin
Antony M Kancidrowski4-Aug-04 1:09
Antony M Kancidrowski4-Aug-04 1:09 
GeneralRe: starting an application at startup, before logging in Pin
Anonymous4-Aug-04 1:27
Anonymous4-Aug-04 1:27 
GeneralRe: starting an application at startup, before logging in Pin
Antony M Kancidrowski4-Aug-04 2:49
Antony M Kancidrowski4-Aug-04 2:49 
GeneralRe: starting an application at startup, before logging in Pin
Anonymous4-Aug-04 1:24
Anonymous4-Aug-04 1:24 
QuestionSend Messages? Pin
Zero_One_ADO3-Aug-04 18:10
Zero_One_ADO3-Aug-04 18:10 
Answerno Pin
bikram singh3-Aug-04 18:44
bikram singh3-Aug-04 18:44 
GeneralVisual C++ WinSNMP API: Pin
Alan Lewis3-Aug-04 16:00
Alan Lewis3-Aug-04 16:00 
GeneralOptimization Pin
Sibilant3-Aug-04 14:54
Sibilant3-Aug-04 14:54 
GeneralVisual C++ static member initialization Pin
Indrawati3-Aug-04 14:25
Indrawati3-Aug-04 14:25 
GeneralRe: Visual C++ static member initialization Pin
User 8348703-Aug-04 22:10
User 8348703-Aug-04 22:10 
GeneralRe: Visual C++ static member initialization Pin
cmk4-Aug-04 0:51
cmk4-Aug-04 0:51 
Indrawati wrote:
Let's say I have a class A. A has a static member whose type is another class, let's call it class B. Usually in my C++ application I declare this static member at the top of A's .cpp file as follows:

B A::instanceofB(aString)

where aString is of std::string type and is the argument for B's constructor.

That works OK and I got the result I wanted. However, ... it seems that instanceofB is never initialized there!


Where/how/when is aString initialized - i hope it's before instanceofB. If not then instanceofB is initialized (at best) with an empty string.

This alone is a potential problem. This is why you try to not to polute the global pool, especially with complex objects, especially with complex constructors.
You have little control over the order globals are initialized across modules.

Basically (if i remember right) globals within a module (c/cpp file) are initialized in the order they appear. Modules have their globals initialized in an effectively undefined order. That is, you don't know if a.cpp globals are initialized before or after b.cpp globals.

You can define some control over this using the #pragma init_seg(...).
#pragma init_seg(compiler) - initialized 1st
#pragma init_seg(lib) - initialized 2nd
#pragma init_seg(user) - initialized 3rd
#pragma init_seg(my_seg) - all initialized after user, but in no other defined order

The main limits with the above are :
- you should really never use compiler unless you know what you are doing
- you can only really use init_seg() once per module and it applies to all globals that follow

This may not be the problem.

Another thing to look at is if instanceofB is being linked in - with the little info provided i can't see why it wouldn't though.

Another thing is that the file i/o state may not be initialized by the time you try to initialize instanceofB. This would prevent B::B() from writing to a file. Try using OutputDebugString().


...cmk

Save the whales - collect the whole set
GeneralRe: Visual C++ static member initialization Pin
Indrawati4-Aug-04 15:09
Indrawati4-Aug-04 15:09 
QuestionHow to create a Point Custom Control Pin
StevenS_Dev3-Aug-04 13:28
StevenS_Dev3-Aug-04 13:28 

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.