D Language
Estructuras
Buscar..
Definiendo un nuevo Struct
Para definir la estructura llamada Persona con una variable de tipo entero edad, altura de variable de tipo entero y variable de tipo flotante ageXHeight:
struct Person {
int age;
int height;
float ageXHeight;
}
Generalmente:
struct structName {
/+ values go here +/
}
Constructores Struct
En D podemos usar constructores para inicializar estructuras como una clase. Para definir una construcción para la estructura declarada en el ejemplo anterior podemos escribir:
struct Person {
this(int age, int height) {
this.age = age;
this.height = height;
this.ageXHeight = cast(float)age * height;
}
}
auto person = Person(18, 180);
Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow