You may have a struct / union constructor to initialize with a given value.
struct PARAMS {
PARAMS(int address, const char *name, const TYPE1 &f) :
Address(address), Name(name), u(f)
{
}
PARAMS(int address, const char *name, const TYPE2 &b) :
Address(address), Name(name), u(b)
{
}
int Address;
char const *Name;
union union_name
{
union_name(const TYPE1 &f) : foo(f) {}
union_name(const TYPE2 &b) : bar(b) {}
TYPE1 foo;
TYPE2 bar;
}u;
};
const PARAMS paramTbl[] {
PARAMS(0x1000, "Param1", TYPE1("abc", 0)),
};
Full example here
source
share