Condividi tramite


Support Aggregate Initialization

The following sample works in Visual C++ .NET 2003 as specified in the standard:

// support_aggregate_initialization1.cpp
struct NotAgg
{
   NotAgg(int)
   {
   }
};

struct Agg
{
   NotAgg mem;
};

int main()
{
   Agg anAggregate = { NotAgg(1) };
}

The following sample works in Visual C++ .NET 2003 as specified in the standard:

// 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;
}

See Also

Other Resources

Visual C++ .NET 2003 Enhanced Compiler Conformance