This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
objeto todo_en_posicion = { 1, 2 }; | |
objeto posicion_y_masa = { {1}, 2 }; | |
objeto solo_la_masa = { {}, 1 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct punto | |
{ | |
int x, y, z; | |
}; | |
// Los agregados pueden componerse de otros agregados | |
struct objeto | |
{ | |
punto posicion; | |
float masa; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// punto es un agregado | |
struct punto | |
{ | |
int x, y, z; | |
}; | |
// punto se puede inicializar con llaves | |
punto p0 = { 1, 2, 3 }; | |
punto p1 = { 1, 2 }; | |
punto p2 = { 1 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A partir dde C++11 | |
struct objeto | |
{ | |
objeto() {} | |
objeto(char c) : caracter(c) {} | |
objeto(int i) : entero(i) {} | |
objeto(long l) : largo(l) {} | |
char caracter = '0'; | |
int entero = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Antes de C++11 | |
struct objeto | |
{ | |
objeto() | |
: caracter('0'), entero(1), largo(2l) {} | |
objeto(char c) | |
: caracter(c), entero(1), largo(2l) {} | |
objeto(int i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Antes de C++11 | |
struct objeto | |
{ | |
objeto() : caracter('0'), entero(1) {} | |
objeto(char c) : caracter(c), entero(1) {} | |
objeto(int i) : caracter('0'), entero(i) {} | |
char caracter; | |
const int entero; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Este objeto es valido antes y despues de C++11 | |
struct objeto | |
{ | |
static const char caracter = '0'; | |
static const int entero = 1; | |
static const long largo = 2l; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Este objeto es valido a partir de C++11 | |
struct objeto | |
{ | |
char caracter = '0'; | |
const int entero = 1; | |
static const long largo = 2l; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std::string HolaMundo("Hola Mundo!"); | |
// auto se deduce como decltype del retorno | |
// que resulta ser const std::string | |
decltype(auto) copia_constante() | |
{ | |
return HolaMundo; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std::string HolaMundo("Hola Mundo!"); | |
// auto se deduce como decltype(HolaMundo) | |
// que resulta ser const std::string | |
auto copia_constante() -> decltype(HolaMundo) | |
{ | |
return HolaMundo; | |
} |