#include <iostream>
#include <cstring>
using namespace std;
union T {
string s;
int n;
public:
T() { new (&s) string; }
~T() { s.~string(); }
};
struct Student{
Student(bool g, int a) : gender(g), age(a) {}
bool gender;
int age;
};
class Singer {
public:
enum Type {STUDENT, NATIVE, FOREIGNER};
Singer(bool g, int a): s(g,a) { t = STUDENT; }
Singer(int i) : id(i) { t = NATIVE; }
Singer(const char* n, int s) {
int size = (s>9) ? 9 : s;
memcpy(name, n, size);
name[s] = '\0';
t = FOREIGNER;
}
~Singer() {}
private:
Type t;
union {
Student s;
int id;
char name[10];
};
};
int main()
{
T t;
Singer a(true, 24);
Singer b(85767);
Singer c("Jack chou", 41);
return 0;
}