C++ Factory Pattern with Heterogenous Constructor Constraint
Have you considered having a factory method for each class that knows how to construct the object from an "array" of parameters read from the file.
That is:
// declared "static" in header file
Class1* Class1::FactoryCreate(int argc, const char** argv)
{
if (argc != 2)
return NULL; // error
int a1 = atoi(argv[0]);
int a2 = atoi(argv[1]);
return new Class1(a1, a2, a3);
}
// declared "static" in header file
Class2* Class2::FactoryCreate(int argc, const char** argv)
{
if (argc != 3)
return NULL; // error
int a1 = atoi(argv[0]);
int a2 = atoi(argv[1]);
int a3 = atoi(argv[2]);
return new Class2(a1, a2, a3);
}