支援的彙總初始設定
下列範例適用於 Visual C++。NET 2003 中所指定的標準:
// support_aggregate_initialization1.cpp
struct NotAgg
{
NotAgg(int)
{
}
};
struct Agg
{
NotAgg mem;
};
int main()
{
Agg anAggregate = { NotAgg(1) };
}
下列範例適用於 Visual C++。NET 2003 中所指定的標準:
// support_aggregate_initialization2.cpp
// compile with: /EHsc
#include <string>
#include <iostream>
using namespace std;
struct MyStruct
{
string strA;
string strB;
} myStrings[2] = { {"a", "b"}, {"c", "d"} };
int main()
{
cout << myStrings[0].strB << endl;
}