had a two part question with regard to below contrived c++ code snippet :
namespace {
struct FieldRecord {
string item_to_fieldname;
bool is_queriable;
};
const FieldRecord g_LookUpTable [] = {
{"employee_name", true},
{ "ssn_no", false},
//etc
};
}
1) if i wanted to implement a lookup table of a structure that is non -pod is the following C style approach error prone or is it neccessary to make the structure FieldRecord a pod i.e replace string with const char* etc
2) how does the FieldRecord structure for the array in the above structure get initialized from the initialization list since i have only a default constructor .
Your FieldRecord isn’t a POD. It is an aggregate, however. To use direct initialization it is sufficient to have an aggregate. If your type becomes a non-aggregate, you’ll need to use a constructor. For aggregates you can just list the values the respective members should get and they’ll get initialized directly, possibly involving a conversions for the members.
The question then becomes: what is an aggregate? Well, it is any class which has neither constructors nor a destructor, no private or protected non-static data members, no base classes, and no virtual functions. If you need any of those, you’ll need to give your type a constructor and construct from there. It is a bit more repetitive but you can still fill an array with these objects. For example: