的成员我haee这一小段代码中,我想创建一个struct员工。员工可以是经理或工人。我无法访问工会成员。这里是我的代码C++ - 不能够访问一个联盟
#include <iostream>
#include <string>
using namespace std;
struct Employee {
int id;
union Person {
struct Manager {
int level;
} manager;
struct Worker {
string department;
} worker;
} company[3];
};
int main() {
Employee one;
one.id = 101;
one.company[0].manager.level = 3;
Employee two;
two.id = 102;
two.company[1].worker.department = "Sales";
Employee three;
three.id = 103;
three.company[2].worker.department = "Marketing";
}
我得到的错误是
arraOfUnions.cc:13:5: error: member 'Employee::Person::Worker Employee::Person::worker' with constructor not allowed in union
arraOfUnions.cc:13:5: error: member 'Employee::Person::Worker Employee::Person::worker' with destructor not allowed in union
arraOfUnions.cc:13:5: error: member 'Employee::Person::Worker Employee::Person::worker' with copy assignment operator not allowed in union
arraOfUnions.cc:13:5: note: unrestricted unions only available with -std=c++0x or -std=gnu++0x
我不知道我在做什么错。请帮忙 谢谢SO
'的std :: string'不能在C++ 03的结合。在C++ 11 – Jarod42
无限制联盟将需要'Person'构造。 – Jarod42
为什么不能串联? –