Skip to content

Instantly share code, notes, and snippets.

@nlguillemot
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nlguillemot/8cee584e7be5da0165ee to your computer and use it in GitHub Desktop.
Save nlguillemot/8cee584e7be5da0165ee to your computer and use it in GitHub Desktop.
value initialized member struct
#include <iostream>
using namespace std;
struct X
{
int a,b,c;
};
struct Y
{
X x{};
X xs[10]{};
int as[10]{};
};
int main()
{
X xs[10]{};
for (X x : xs)
{
cout << "{" << x.a << "," << x.b << "," << x.c << "} ";
}
cout << "\n";
Y y;
cout << "{" << y.x.a << "," << y.x.b << "," << y.x.c << "}\n";
for (X x : y.xs)
{
cout << "{" << x.a << "," << x.b << "," << x.c << "} ";
}
cout << "\n";
for (int a : y.as)
{
cout << a << " ";
}
cout << "\n";
}
Compiled with /EHsc /nologo /W4
main.cpp
Compilation successful!
Total compilation time: 109ms
{0,0,0} {0,0,0} {0,0,0} {0,0,0} {0,0,0} {0,0,0} {0,0,0} {0,0,0} {0,0,0} {0,0,0}
{0,0,0}
{49496989,-1238296826,0} {0,0,0} {1919956480,0,0} {0,50987008,0} {-960810910,50789928,49552880} {50987008,0,8} {5,49677504,14} {50789948,49546403,49679328} {50790016,49546421,4} {49487600,-1238296646,50789996}
0 0 0 0 0 0 0 0 0 0
Total execution time: 359ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment