So we have simple interface base class:
class animal {
public:
animal(int age) : age_(age) {
}
virtual ~animal(void) {
}
virtual std::string get_name(v
I'd just make it so that the main()
is trivial. Like
int main()
{
int default_age = 4;
return puma(default_age).run();
}
and leave it at that.
int main()
{
int default_age = 4;
SERVICECLASS *an_animal = new SERVICECLASS(default_age);
std::cout << "anmal "<< an_animal->get_name << " created. Its age is " << an_animal->get_age << std::endl;
std::cin.get();
}
Then compile with (your compiler's equivalent of) -DSERVICECLASS=puma
, or have a file called something like "config.h" which is included by main
, and that you can edit without having to edit any other code.
Then you can define your animal classes however you like. If you want to define classes like this:
#define STRINGIZE_(ARG) #ARG
#define EXPAND_AND_STRINGIZE(ARG) STRINGIZE(ARG)
class SERVICECLASS: public animal {
public:
SERVICECLASS(int age) : animal(age) {}
virtual std::string get_name() {
return EXPAND_AND_STRINGIZE(SERVICECLASS);
}
};
then you can. But surely your classes do more than just hard-code a string, so I'd expect different animals to need separate definitions even if they have a certain amount in common.