Click here to Skip to main content
15,896,153 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralMultiline toolbar button Pin
blase_313-Aug-04 13:23
blase_313-Aug-04 13:23 
Generaltotal number digit in string name. Pin
pnpfriend3-Aug-04 11:43
pnpfriend3-Aug-04 11:43 
GeneralRe: total number digit in string name. Pin
Bhaskar4-Aug-04 0:37
Bhaskar4-Aug-04 0:37 
GeneralRe: total number digit in string name. Pin
Ivan Cachicatari4-Aug-04 4:02
Ivan Cachicatari4-Aug-04 4:02 
GeneralRe: total number digit in string name. Pin
pnpfriend4-Aug-04 4:56
pnpfriend4-Aug-04 4:56 
GeneralLoading Bitmaps Pin
Don123-Aug-04 10:57
Don123-Aug-04 10:57 
GeneralOpen With... Dialog in Windows Explorer Pin
otrcomm3-Aug-04 10:16
otrcomm3-Aug-04 10:16 
GeneralRe: Open With... Dialog in Windows Explorer Pin
palbano3-Aug-04 10:33
palbano3-Aug-04 10:33 
GeneralRe: Open With... Dialog in Windows Explorer Pin
otrcomm3-Aug-04 12:04
otrcomm3-Aug-04 12:04 
GeneralRe: Open With... Dialog in Windows Explorer Pin
palbano4-Aug-04 10:59
palbano4-Aug-04 10:59 
GeneralRe: Open With... Dialog in Windows Explorer Pin
otrcomm4-Aug-04 16:15
otrcomm4-Aug-04 16:15 
GeneralRe: Open With... Dialog in Windows Explorer Pin
palbano4-Aug-04 16:33
palbano4-Aug-04 16:33 
GeneralRe: Open With... Dialog in Windows Explorer Pin
otrcomm4-Aug-04 18:33
otrcomm4-Aug-04 18:33 
Generallooking for MS (?) MFC sample program. Pin
Maximilien3-Aug-04 10:05
Maximilien3-Aug-04 10:05 
GeneralRe: looking for MS (?) MFC sample program. Pin
Johan Rosengren3-Aug-04 10:43
Johan Rosengren3-Aug-04 10:43 

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.