This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ Static String Causes Segmentation Fault


Thanks Theodore.  I like this approach.  It keeps all the definitions pertaining to
the class (especially private static strings) in the same source file as the rest of
the class, and it avoids using a "Global.cpp" to hold all of the static member
definitions from all of the classes in the system.  I tested it with the sample
program, and it works!!

Regards,

Ben


Theodore Papadopoulo wrote:

----- Original Message ----
> Ben Atkinson wrote:
> > Thanks for the response, Ian.   With an eye toward correcting the problem
> > in my source code, does C++ make any guarantees about global
> > constructors in the same source?
> >  
> A more robust scheme is to create a function (or static member function) that 
> returns the
> static string, and using this function to get the string...
> 
> class XXX {
> ...
>    static std:string& mystring() { static std::string foo = "whatever"; return 
> foo; }
> 
> ...
> };



      


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]