chr*_*irk 5 c++ templates struct optional-variables
我有许多具体结构,我想将字段指定为可选(现在或不存在).只是想知道人们有什么想法来实现这一目标.这是一个示例结构(字段也可以是其他结构,甚至是结构的向量):
struct LogonMessage_t
{
Header_t header; // this points to another struct containing all primitives
std::string username;
std::string password;
std::vector<LogonOption_t> LogonOptions;
int subaccountid;
std::string Text;
}
Run Code Online (Sandbox Code Playgroud)
我想将所有字段默认为不存在并逐个启用它们,也许是在它们的setter中.由于生成了这些结构,因此优选通用方法.
我到目前为止的想法是:
顺便说一句,使用地图或其他STL容器来封装字段在这里不起作用,它们需要是具体的结构.