const char [] troubles with class def's

Started by
11 comments, last by sp00nfed 22 years, 5 months ago
In such cases, we use static member variables. Static member variables (note that they aren''t the same thing as static variables!) belong to the class; there is only one copy regardless of how many instances of the class exist. It''s very useful for reference counting, for example. It is precisely because only one copy exists for the entire class that it must be initialized at file scope (outside of the class declaration, but it can be in the same file - after the class declaration).

Static variables are variables allocated when first encountered which do not lose their value and are not deallocated for the duration of the program. This is very useful for certain "reentrant" functions (I remember using them for timeslice''ing under DOS).
Advertisement
To Stoffel: You're using VC++, am I right? This behavior is a "feature" of the MS implementation, but AFAIK it should be possible in ANSI C++.
Have a look at http://support.microsoft.com/support/kb/articles/Q241/5/69.ASP.

Edited by - VolkerG on October 22, 2001 3:36:02 PM
Ah, right you are. My bad. Maybe it''ll be fixed in .Net. =)

This topic is closed to new replies.

Advertisement