我被告知要编写一个程序,该程序创建一个联合和结构,然后创建联合和结构的二元素数组并填充它们的字段。我创建了一个联合和一个结构,但是如何在数组中填充它们的字段?
#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;
}
我试过 un[0]->i1=i; 但这不是正确的方法。