수색…
새로운 Struct 정의하기
정수형 변수 age, 정수형 변수 height 및 float 형 변수 ageXHeight를 사용하여 Person이라는 구조체를 정의하려면 다음을 수행하십시오.
struct Person {
int age;
int height;
float ageXHeight;
}
일반적으로:
struct structName {
/+ values go here +/
}
Struct 생성자
D에서 생성자를 사용하여 클래스처럼 구조체를 초기화 할 수 있습니다. 앞의 예제에서 선언 된 구조체의 구조체를 정의하기 위해 다음과 같이 입력 할 수 있습니다.
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
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow