I would like to have a C++ class that gets initialized from a file that contains a bunch of data, reads the data, and stores it as const data members.
What I currently do is
MyClass(const std::string & fileName):
datum0(),
datum1(),
datum2()
{
this->read(fileName);
// read() sets all datumX data members.
}
This has the disadvantage that the datumXs cannot be marked const anymore since they are set up after the actual initialization step.
What would be a good pattern here?
Instead of set of datumX members – use struct with these members which have constructor from file. And make this struct const data member of your class: