Hola, el ejemplo 16.3, de las uniones no me compila.<br>ejemplo D = {"hasta pronto"}; // Aqui me lanza el error: error: in C++98 ‘D’ must be initialized by constructor, not by ‘{...}’<br><br>Y warnings: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x<br>
<br>El ejemplo es este:<br>#include <iostream><br>#include <cstring><br><br>using namespace std;<br><br>union ejemplo {<br> int x;<br> double d;<br> char cad[8];<br> ejemplo(int i) : x(i) {}<br> ejemplo(double n) : d(n) {}<br>
ejemplo(const char *c) {<br> strncpy(cad, c, 7);<br> cad[7] = 0;<br> } <br>};<br><br>int main() {<br> ejemplo A(23);<br> ejemplo B(123.323);<br> ejemplo C("hola a todos");<br> ejemplo D = {"hasta pronto"};<br>
<br> cout << "A: " << A.x << endl;<br> cout << "B: " << B.d << endl;<br> cout << "C: " << C.cad << endl;<br> cout << "D: " << D.cad << endl;<br>
<br> return 0;<br>}<br clear="all"><br>-- <br><b style="font-family: courier new,monospace; color: rgb(51, 102, 255);"><i>Saludos, Alejandro A.B.<br>Mi blog: <a href="http://bashyc.blogspot.com/" target="_blank">http://bashyc.blogspot.com/</a></i></b><br>
<br>