Is this program supposed to correctly initialize the string, in C++03?
#include <iostream>
#include <string>
struct A
{
std::string s;
};
int main()
{
A a = { };
std::cout << a.s.size() << std::endl;
}
Using bcc32 6.70, the output is 256 , and inspecting the string in the debugger, its internal pointers appear to be garbage addresses.
Ais an aggregate and C++03 allows initialization of aggregates using a braced initializer-list. If the initializer-list is empty, then each member of the aggregate is value initialized.From C++03 [dcl.init.aggr]/8
In your example the
std::stringmember should be default initialized.