我被告知编写一个程序,该程序创建一个并集和结构,然后创建由两个元素组成的并集和结构数组,并填充它们的字段。我创建了一个并集和一个结构,但是如何将它们的字段填充为数组?
#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;
}
Run Code Online (Sandbox Code Playgroud)
我试过un [0]-> i1 = i; 但这不是正确的方法。