---------------
struct Address {
    const char*name;   // "Jim Dandy"
    int number;        // 61
    const char*street; // "South St"
    const char*town;   // "New Providence"
    char state[2];     // 'N' 'J'
    const char*zip;    // "07974"
};
---------------
void f()
{
    Address jd;
    jd.name = "Jim Dandy";
    jd.number = 61;
}
---------------
Address jd = {
    "Jim Dandy",
    61, "South St",
    "New Providence",
    {'N','J'}, "07974"
};
---------------
void print_addr(Address*p)
{
    cout << p->name << '\n'
    << p->number << ' ' << p->street << '\n'
    << p->town << '\n'
    << p->state[0] << p->state[1] << ' ' << p->zip << '\n';
}
---------------
void print_addr2(const Address& r)
{
    cout << r.name << '\n'
        << r.number << ' ' << r.street << '\n'
        << r.town << '\n'
        << r    .state[0] << r.state[1] << ' ' << r.zip << '\n';
}
---------------
Address current;

Address set_current(Address next)
{
    address prev = current;
    current = next;
    return prev;
}
---------------
struct Readout {
    char hour; // [0:23]
    int value;
    char seq;  // znak oznaczajcy sekwencj ['a':'z']
};
---------------
struct Readout {
    int value;
    char hour; // [0:23]
    char seq;  // znak oznaczajcy sekwencj ['a':'z']
};
---------------
struct Link {
    Link*previous;
    Link*successor;
};
---------------
struct No_good {
    No_good member; // bd: rekurencyjna definicja
};
---------------
struct List; // deklaracja nazwy struktury List, ktra zostanie zdefiniowana pniej

struct Link {
    Link*pre;
    Link*suc;
    List*member_of;
    int data;
};

struct List {
    Link*head;
};
---------------
struct S; // S jest nazw jakiego typu

extern S a;
S f();
void g(S);
S*h(S*);
---------------
void k(S*p)
{
    Sa;         // bd: nie zdefiniowano S; do alokacji potrzebny jest rozmiar
    f();        // bd: nie zdefiniowano S; aby zwrci warto, potrzebny jest rozmiar
    g(a);       // bd: nie zdefiniowano S; aby przekaza argument, potrzebny jest rozmiar
    p->m = 7;   // bd: nie zdefiniowano S; nieznana nazwa skadowej
    S*q = h(p); // OK: wskaniki mona alokowa i przekazywa
    q->m = 7;   // bd: nie zdefiniowano S; nieznana nazwa skadowej
}
---------------
struct stat { /*...*/ };
int stat(char*name , struct stat*buf);
---------------
struct Points {
    vector<Point> elem; // musi zawiera przynajmniej jeden obiekt Point
    Points(Point p0) { elem.push_back(p0);}
    Points(Point p0, Point p1) { elem.push_back(p0); elem.push_back(p1); }
    //...
};

Points x0;                         // bd: brak konstruktora domylnego
Points x1{ {100,200} };            // jeden obiekt Point
Points x1{ {100,200}, {300,400} }; // dwa obiekty Point
---------------
struct Point {
    int x, y;
};

Point p0;       // niebezpieczestwo: niezainicjowany, jeli w zakresie lokalnym (6.3.5.1)
Point p1 {};    // domylna konstrukcja: {{},{}}; tzn. {0.0}
Point p2 {1};   // druga skadowa jest tworzona domylnie: {1,{}}; tzn. {1,0}
Point p3 {1,2}; // {1,2}
---------------
struct Address {
    string name;   // "Jim Dandy"
    int number;    // 61
    string street; // "South St"
    string town;   // "New Providence"
    char state[2]; // 'N' 'J'
    char zip[5];   // 07974
    Address(const string n, int nu, const string& s, const string& t, const string& st, int z);
};
---------------
Address jd = {
    "Jim Dandy",
    61, "South St",
    "New Providence",
    "NJ", 7974 // (07974 oznaczaoby warto semkow; 6.2.4.1)
};
---------------
Address::Address(const string& n, int nu, const string& s, const string& t, const string& st, int z)
                   // weryfikacja kodu pocztowego
    :name{n},
    number{nu},
    street{s},
    town{t}
{
    if (st.size()!=2)
        error("Skrt nazwy stanu powinien by dwuliterowy")
    state = {st[0],st[1]}; // zapisanie kodu pocztowego jako znakw
    ostringstream ost;     // strumie wyjciowy acuchw; zobacz 38.4.2
    ost << z;              // wydobycie znakw z int
    string zi {ost.str()};
    switch (zi.siz e()) {
    case 5:
        zip = {zi[0], zi[1], zi[2], zi[3], zi[4]};
        break;
    case 4: // zaczyna si od '0'
        zip = {'0', zi[0], zi[1], zi[2], zi[3]};
        break;
    default:
        error("Niespodziewany format kodu pocztowego");
    }
    //... Sprawdzenie, czy kod jest sensowny...
}
---------------
struct Point {
    int x,y
};

Point points[3] {{1,2},{3,4},{5,6}};
int x2 = points[2].x;

struct Array {
    Point elem[3];
};

Array points2 {{1,2},{3,4},{5,6}};
int y2 = points2.elem[2].y;
---------------
Array shift(Array a, Point p)
{
    for (int i=0; i!=3; ++i) {
        a.elem[i].x += p.x;
        a.elem[i].y += p.y;
    }
    return a;
}

Array ax = shift(points2,{10,20});
---------------
template<typename T, siz e_tN>
struct array { // uproszczona wersja (patrz 34.2.1)
    T elem[N];

    T*begin() noexcept { return elem; }
    const T*begin() const noexcept {return elem; }
    T*end() noexcept { return elem+N; }
    const T*end() const noexcept { return elem+N; }

    constexpr size_t size() noexcept;

    T& operator[](size_t n) { return elem[n]; }
    const T& operator[](size_type n) const { return elem[n]; }

    T*data() noexcept { return elem; }
    const T*data() const noexcept { return elem; }

    //...
};
---------------
struct Point {
    int x,y
};

using Array = array<Point,3>; // tablica 3 obiektw Point

Array points {{1,2},{3,4},{5,6}};
int x2 = points[2].x;
int y2 = points[2].y;

Array shift(Array a, Point p)
{
    for (int i=0; i!=a.size(); ++i) {
        a[i].x += p.x;
        a[i].y += p.y;
    }
    return a;
}

Array ax = shift(points,{10,20});
---------------
ostream& operator<<(ostream& os, Point p)
{
    return os << '{' << p.x << ',' << p.y << '}';
}

void print(Point a[],int s) // wymg okrelenia liczby elementw
{
    for (int i=0; i!=s; ++i)
        cout << a[i] << '\n';
}

template<typename T, int N>
void print(array<T,N>& a)
{
    for (int i=0; i!=a.size(); ++i)
        cout << a[i] << '\n';
}

Point point1[] = {{1,2},{3,4},{5,6}};        // 3 elementy
array<Point,3> point2 = {{1,2},{3,4},{5,6}}; // 3 elementy

void f()
{
    print(point1,4); // 4 to powany bd
    print(point2);
}
---------------
Point point1[] = {{1,2},{3,4},{5,6}};        // 3 elementy
array<Point,3> point2 = {{1,2},{3,4},{5,6}}; // 3 elementy
array<Point> point3 = {{1,2},{3,4},{5,6}};   // bd: nie podano liczby elementw
---------------
struct S1 { int a; };
struct S2 { int a; };
---------------
S1 x;
S2 y = x;  // bd: niedopasowanie typw
---------------
S1 x;
int i = x; // bd: niedopasowanie typw
---------------
struct S0 { };                                               // POD
struct S1 { int a; };                                        // POD
struct S2 { int a; S2(int aa) : a(aa) { } };                 // nie POD (brak domylnego konstruktora)
struct S3 { int a; S3(int aa) : a(aa) { } S3() {} };         // POD (konstruktor domylny 
                                                             // zdefiniowany przez uytkownika)
struct S4 { int a; S4(int aa) : a(aa) { } S4() = default; }; // POD
struct S5 { virtual void f(); /*...*/ };                        // nie POD (zawiera funkcj wirtualn)

struct S6 : S1 { };        // POD
struct S7 : S0 { int b; }; // POD
struct S8 : S1 { int b; }; // nie POD (dane zarwno w S1, jak i S8)
struct S9 : S0, S1 {};     // POD
---------------
template<typename T>
    void mycopy(T*to, const T*from, int count);
---------------
template<typename T>
void mycopy(T*to, const T*from, int count)
{
    if (is_pod<T>::value)
        memcpy(to,from,count*siz eof(T));
    else
        for (int i=0; i!=count; ++i)
            to[i]=from[i];
}
---------------
struct PPN {               // Physical Page Number R6000
    unsigned int PFN : 22; // Page Frame Number
    int : 3;               // nieuywane
    unsigned int CCA : 3;  // Cache Coherency Algorithm
    bool nonreachable : 1;
    bool dirty : 1;
    bool valid : 1;
    bool global : 1;
};
---------------
void part_of_VM_system(PPN*p)
{
    // ...
    if (p->dirty) { // zmieniono zawarto
        // kopiowanie na dysk
        p->dir ty=0;
    }
}
---------------
enum Type { str, num };

struct Entry {
    char*name;
    Type t;
    char*s; // uycie s, jeeli t==str
    int i;  // uycie i, jeeli t==num
};

void f(Entry*p)
{
    if (p->t == str)
        cout << p->s;
    // ...
}
---------------
union Value {
    char*s;
    int i;
};
---------------
struct Entry {
    char*name;
    Type t;
    Value v; // uycie v.s, jeeli t==str; uycie v.i, jeeli t==num
};

void f(Entry*p)
{
    if (p->t == str)
    cout << p->v.s;
    // ...
}
---------------
union Fudge {
    int i;
    int*p;
};

int*cheat(int i)
{
    Fudge a;
    a.i = i;
    return a.p; // le
}
---------------
int*cheat2(int i)
{
    return reinterpret_cast<int*>(i); // od razu wida, e to nieeleganckie i niebezpieczne
}
---------------
void f(Entry a)
{
    Entry b=a;
};
---------------
union U {
    int m1;
    complex<double> m2; // complex ma konstruktor
    string m3;          // string ma konstruktor (pilnujcy wanego niezmiennika)
};
---------------
void f2(U x)
{
    Uu;               // bd: ktry domylny konstruktor?
    Uu2=x;            // bd: ktry konstruktor kopiujcy?
    u.m1 = 1;         // przypisanie do skadowej int
    string s = u.m3;  // katastrofa: odczyt ze skadowej acuchowej
    return;           // bd: ktre destruktory s wywoywane dla x, u oraz u2?
}
---------------
union U2 {
    int a;
    const char*p {""};
};

U2 x1;     // domylna inicjacja do x1.p == ""
U2 x2 {7}; // x2.a == 7
---------------
class Entry2 { // dwie alternatywne reprezentacje reprezentowane jako unia
private:
    enum class Tag { number, text };
    Tag type;  // wyrnik

    union {    // reprezentacja
        int i;
        string s; // typ string ma domylny konstruktor, operacje kopiowania oraz destruktor
    };
public:
    struct Bad_entry { }; // uywane dla wyjtkw

    string name;

    ~Entry2();
    Entry2& operator=(const Entry2&); // potrzebne ze wzgldu na wariant z typem string
    Entry2(const Entr y2&);
    // ...

    int number() const;
    string text() const;

    void set_number(int n);
    void set_text(const string&);
    // ...
};
---------------
int Entry2::number() const
{
    if (type!=Tag::number) throw Bad_entry{};
    return i;
};

string Entry2::text() const
{
    if (type!=Tag::text) throw Bad_entry{};
    return s;
};
---------------
void Entry2::set_number(int n)
{
    if (type==Tag::text) {
        s.~string(); // jawne usunicie acucha (11.2.4)
        type = Tag::number;
    }
    i=n;
}

void Entry2::set_text(const string& ss)
{
    if (type==Tag::text)
        s = ss;
    else {
        new(&s) string{ss}; // tzw. placement new: jawne konstruowanie acucha (11.2.4)
        type = Tag::text;
    }
}
---------------
Entry2& Entry2::operator=(const Entry2& e) // potrzebne ze wzgldu na wariant z typem string
{
    if (type==Tag::text && e.type==Tag::text) {
        s = e.s; // zwyke przypisanie acucha
        return*this;
    }

if (type==Tag::text) s.~string(); // jawne usunicie (11.2.4)

    switch (e.type) {
    case Tag::number:
        i=e.i;
        break;
    case Tag::text:
        new(&s)(e .s); // placement new: jawna konstrukcja (11.2.4)
        type = e.type;
    }

    return*this;
}
---------------
Entry2::~Entry2()
{
    if (type==Tag::text) s.~string(); // jawne usunicie (11.2.4)
}
---------------
enum class Color { red, green, blue};
---------------
enum class Traffic_light { red, yellow, green };
enum class Warning { green, yellow, orange , red }; // poziomy alarmu poarowego

Warning a1 = 7;              // bd: nie mona wykona konwersji int->Warning
int a2 = green;              // bd: green nie naley do zakresu
int a3 = Warning::green;     // bd: nie mona wykona konwersji Warning->int
Warning a4 = Warning::green; // OK

void f(Traffic_light x)
{
    if (x == 9) { /*...*/ }                  // bd: 9 nie naley do Traffic_light
    if (x == red) { /*...*/ }                // bd: brak enumeratora red w zakresie
    if (x == Warning::red) { /*...*/ }       // bd: x to nie Warning
    if (x == Traffic_light::red) { /*...*/ } // OK
}
---------------
enum class Warning : int { green, yellow, orange, red }; // sizeof(War ning)==sizeof(int)
---------------
enum class Warning : char { green, yellow, orange , red }; // sizeof(War ning)==1
---------------
static_cast<int>(Warning::green)==0
static_cast<int>(Warning::yellow)==1
static_cast<int>(Warning::orange)==2
static_cast<int>(Warning::red)==3
---------------
void f(Warning key)
{
    switch (key) {
    case Warning::green:
        // jakie dziaania
        break;
    case Warning::orange:
        // jakie dziaania
        break;
    case Warning::red:
        // jakie dziaania
        break;
    }
}
---------------
enum class Printer_flags {
    acknowledge=1,
    paper_empty=2,
    busy=4,
    out_of_black=8,
    out_of_color=16,
    //...
};
---------------
constexpr Printer_flags operator|(Printer_flags a, Printer_flags b)
{
    return static_cast<Printer_flags>(static_cast<int>(a))|static_cast<int>(b));
}
constexpr Printer_flags operator&(Printer_flags a, Printer_flags b)
{
    return static_cast<Printer_flags>(static_cast<int>(a))&static_cast<int>(b));
}
---------------
void try_to_print(Printer_flags x)
{
    if (x&Printer_flags::acknowledg e) {
        // ...
    }
    else if (x&Printer_flags::busy) {
        // ...
    }
    else if (x&(Printer_flags::out_of_black|Printer_flags::out_of_color)) {
        // albo skoczy si czarny, albo kolorowy
        // ...
    }
    // ...
}
---------------
void g(Printer_flags x)
{
    switch (x) {
    case Printer_flags::acknowledg e:
        // ...
        break;
    case Printer_flags::busy:
        // ...
        break;
    case Printer_flags::out_of_black:
        // ...
        break;
    case Printer_flags::out_of_color:
        // ...
        break;
    case Printer_flags::out_of_black&Printer_flags::out_of_color:
        // skoczy si czarny *i* kolorowy
        // ...
        break;
    }
    // ...
}
---------------
enum class Color_code : char;  // deklaracja
void foobar(Color_code*p);     // uycie deklaracji
//...
enum class Color_code : char { // definicja
    red, yellow, green, blue
};
---------------
enum class Flag : char{ x=1, y=2, z=4, e=8 };

Flag f0 {};                       // f0 ma domyln warto 0
Flag f1 = 5;                      // bd typu: 5 nie jest typu Flag
Flag f2 = Flag{5};                // bd: nie mona stosowa konwersji zawajcej
Flag f3 = static_cast<Flag>(5);   // rozwizanie siowe
Flag f4 = static_cast<Flag>(999); // bd: 999 nie jest wartoci typu char (moe to nie zosta wychwycone)
---------------
int i = static_cast<int>(Flag::y);   // i ma warto 2
char c = static_cast<char>(Flag::e); // c ma warto 8
---------------
enum Traffic_light { red, yellow, green };
enum Warning { green, yellow, orange, red }; // poziomy alarmu poarowego

// bd: dwie definicje yellow (taka sama warto)
// bd: dwie definicje red (dwie rne wartoci)

Warning a1 = 7;              // bd: nie mona wykona konwersji int->Warning
int a2 = green;              // OK: green znajduje si w dostpnym zakresie i konwertuje si na int
int a3 = Warning::green;     // OK: konwersja Warning->int
Warning a4 = Warning::green; // OK

void f(Traffic_light x)
{
    if (x == 9) { /*...*/ }                  // OK (ale Traffic_light nie zawiera wartoci)
    if (x == red) { /*...*/ }                // bd: w zakresie s dwa enumeratory red
    if (x == Warning::red) { /*...*/ }       // OK (ojej!)
    if (x == Traffic_light::red) { /*...*/ } // OK
}
---------------
enum Traffic_light { tl_red, tl_yellow, tl_green };
enum Warning { green, yellow, orange, red }; // poziomy alarmu poarowego
void f(Traffic_light x)
{
    if (x == red) { /*...*/ }                   // OK (ojej!)
    if (x == Warning::red) { /*...*/ }          // OK (ojej!)
    if (x == Traffic_light::red) { /*...*/ } // bd: red nie naley do Traffic_light
}
---------------
enum Traffic_light : char { tl_red, tl_yellow, tl_green }; // typ tego wyliczenia to char

enum Color_code : char;    // deklaracja
void foobar(Color_code*p); // uycie deklaracji
//...
enum Color_code : char { red, yellow, green, blue }; // definicja
---------------
enum E1 { dark, light };              // przedzia 0:1
enum E2 { a = 3, b = 9 };             // przedzia 0:15
enum E3 { min = -10, max = 1000000 }; // przedzia -1048576:1048575
---------------
enum Flag { x=1, y=2, z=4, e=8 }; // przedzia 0:15

Flag f0 {};                       // f0 ma domyln warto 0
Flag f1=5;                        // bd typu: 5 nie jest typu Flag
Flag f2 = Flag{5};                // bd: nie mona jawnie konwertowa int na Flag
Flag f2 = static_cast<Flag>(5);   // OK: 5 mieci si w zakresie Flag
Flag f3 = static_cast<Flag>(z|e); // OK: 12 mieci si w zakresie Flag
Flag f4 = static_cast<Flag>(99);  // niezdefiniowany wynik: 99 nie mieci si w zakresie Flag
---------------
enum { arrow_up=1, arrow_down, arrow_si
---------------
deways };