Static virtual functions?
I appear to need a static virtual member function, which it seems I
can't have. I'm trying to do something like the following:
class Base {
virtual void writetofile() = 0;
virtual void readfromfile() = 0;
(something here) char *name(); };
class Deriv1 : public Base {
virtual void writetofile();
virtual void readfromfile();
(ditto) char *name() { return "Deriv1"; } };
class Deriv2 : public Base {
virtual void writetofile();
virtual void readfromfile();
(ditto) char *name() { return "Deriv2"; } };
Now I want to write them to a file doing something like:
write (x -> name); x -> writetofile();
which requires name to be a virtual function. But I also want to do:
read(type);
if (strcmp(type, Deriv1::name) == 0) { x = new Deriv1; x ->
readfromfile(); }
if (strcmp(type, Deriv2::name) == 0) { x = new Deriv2; x ->
readfromfile(); }
which requires name to be a static member function.
Any suggestions? I want to avoid having to duplicate the names in
different places.
Thanks in advance.
Paul.