c++ - Using a free "char const*" at static initialization time -
The initial order of free objects is undefined in C ++ but what about the following?
named place foo {char const * str = "hey"; Structure A {A () {cout & lt; & Lt; Str; }} Obj; } Is it still an undetermined behavior, or is there a special provision for pointers started with string literals?
Apart from this : What if str was a type "four const []"? And if it was a std :: string
Even if they were located in different translation units, the initial order Is still defined
That's because str is started with a constant expression ( address continuous expression ) and str has pod-type, it will still be correct if you have an array but if you had a std :: string , then it would not be true now those dynamically started New have (because std :: string is a non-POD).
Thus, if your str was a std :: string , then if you define obj then you are undefined In practice, a separate translation unit will run, but for the list you are listed on, this will be the only issue that will cause trouble.
Comments
Post a Comment