POD can have private/protected members
Because of protected members, it is impossible to initialize struct like this:
struct SomePOD_t {
protected:
char *p_begin;
char *p_end;
};
void foo() {
const char *STR = "Some data";
SomePOD_t data = { STR, STR + strlen(STR)+1 }; // error "no mathing constructor for
// initialization of SomePOD_t"
}
My question is how to make easier passing POD types to functions:
// gonna use this foo
void foo_uses_some_pod(SomePOD_t data);
void foo()
{
const char *STR = "Some data";
//error "no matching function for call to 'foo_uses_some_pod'"
// "candidate function not viable: cannot convert initializer list argument to 'SomePOD_t'"
foo_uses_some_pod({STR, STR + strlen(STR)+1});
//ok, if SomePOD_t::static_built_function is defined.
foo_uses_some_pod(SomePOD_t::static_built_function(STR, STR + strlen(STR)+1));
}
I think explicit type mapping SomePOD_t{STR, STR + strlen(STR)+1}
in the function call is a good practice, but excess static_built_function
in SomePOD_t::static_built_function(STR, STR + strlen(STR)+1)
is too much.
If I add constructor to SomePOD_t
it will not be POD anymore, so all types, that use SomePOD_t
will become non-POD too and I have to add constructors for every type with SomePOD_t
as member, or type with type that has type ... ... that has SomePOD_t
as member.
Can type be POD, have private/protected members and support initializer-list inititalization? How?