유니온과 구조체를 만드는 프로그램을 작성한 다음 유니온과 구조체의 두 요소 배열을 만들고 필드를 채 웁니다. 나는 유니온과 구조체를 만들었지 만 배열로 필드를 채우는 방법은 무엇입니까?C++ 유니온과 구조체 테이블
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
union complex;
union complex{
int i1;
long double ld1;
} u;
struct Person {
char* name;
int age;
bool sex;
void show(){
printf("name %s, age %2.0d, sex %1d\n",
name , age, sex);
};
} person;
int main(void)
{
Person *o = new Person[2];
complex *un = new complex[2];
un[0]->i1=i;
system("pause");
return 0;
}
나는 [0] -> i1 = i; 그러나 이것을하는 적절한 방법이 아닙니다.
새 배열을 만들 필요가 없습니다. –