I've read about POD objects in C++. I wanna have a POD struct to be written into a file. So it should have only public data with no ctors/dtors etc. But as far as i know it can have static function in it. So can I use "named constructor idiom" here? I need dynamic initialization, but I don't want to duplicate arguments checking at every struct initialization Here is a simple example (it's just simple example, not a working code):
struct A
{
int day;
int mouth;
int year;
static A MakeA(const int day, const int month, const int year)
{
// some simple arguments chech
if ( !(day >= 1 && day <= 31) || !(month >=1 && month <=12) || !(year <= 2010) )
throw std::exception();
A result;
result.day = day;
result.month = month;
result.year = year;
return result;
}
};
So I have some kind of a constructor and a POD structure that I can simply fwrite to a file? It it correct?