C++ initializer lists with unions, why different results?
I have the following program:

    #include <initializer_list>
    #include <iostream>
    
    class A;
    class nih {
    public:
    	virtual void apply(A & a) const { std::cout << "generic" << std::endl; };
    };
    
    union niit;
    class A {
    public:
      int s; char kau;
      A() : s(1), kau('-') { }
      A(std::initializer_list<niit> k);
    };
    
    class sn : public nih { int s; public: sn(int x) : s(x) { }
      virtual void apply(A & a) const { a.s=s; } };
    class kaun : public nih { char kau; public: kaun(char x) : kau(x) { }
      virtual void apply(A & a) const { a.kau=kau; } };
    union niit { sn sni; kaun kauni; nih nihi;
      niit(const sn & s) : sni(s) { }
      niit(const kaun & k) : kauni(k) { }
    };
    
    A::A(std::initializer_list<niit> k) { 
      const niit *n=k.begin();
      for(int i=0;i<k.size();i++) {
        const nih* p=&n[i].nihi;
        p->apply(*this);
      }
    }
    
    int main(int argc, char**argv) {
      A r {kaun('a'),sn(91)};
      std::cout << r.s << r.kau << std::endl;
    }
I get the expected result, which is `91a`. However, if I change the line

    p->apply(*this);

to the following:

    ((const nih*)(&n[i].nihi))->apply(*this);

which should be replacement with an equivalent value, it no longer works, and instead it prints:

    generic
    generic
    0

That is, it executes the generic method from `nih`. Why is that? I tried gcc 4.6 with option `-std=c++0x`, in case it matters.
C++ initializer lists with unions, why different results?
===

I have the following program:

    #include <initializer_list>
    #include <iostream>
    
    class A;
    class nih {
    public:
    	virtual void apply(A & a) const { std::cout << "generic" << std::endl; };
    };
    
    union niit;
    class A {
    public:
      int s; char kau;
      A() : s(1), kau('-') { }
      A(std::initializer_list<niit> k);
    };
    
    class sn : public nih { int s; public: sn(int x) : s(x) { }
      virtual void apply(A & a) const { a.s=s; } };
    class kaun : public nih { char kau; public: kaun(char x) : kau(x) { }
      virtual void apply(A & a) const { a.kau=kau; } };
    union niit { sn sni; kaun kauni; nih nihi;
      niit(const sn & s) : sni(s) { }
      niit(const kaun & k) : kauni(k) { }
    };
    
    A::A(std::initializer_list<niit> k) { 
      const niit *n=k.begin();
      for(int i=0;i<k.size();i++) {
        const nih* p=&n[i].nihi;
        p->apply(*this);
      }
    }
    
    int main(int argc, char**argv) {
      A r {kaun('a'),sn(91)};
      std::cout << r.s << r.kau << std::endl;
    }
I get the expected result, which is `91a`. However, if I change the line

    p->apply(*this);

to the following:

    ((const nih*)(&n[i].nihi))->apply(*this);

which should be replacement with an equivalent value, it no longer works, and instead it prints:

    generic
    generic
    0

That is, it executes the generic method from `nih`. Why is that? I tried gcc 4.6 with option `-std=c++0x`, in case it matters.