Search code examples
c++fileabstract-class

How do you write and read an abstract class pointer to a file in c++?


I have several classes that all inherit the same interface. These classes are instantiated and saved in interface pointers. For example:

struct Class {
private:
    Function* function;
};

I need to save the function to a file, and am wondering if saving the function as (*function), I will need to add an enum or do instance checking? The function objects contain one method that needs to be called from the abstract function class after loading the file and I want to make sure I am able to call that function after loading the file.


Solution

  • The only thing you can do: Make a list of all the function pointers that you would want to store, assign an unchangeable unique number to each, write that number to the file, and upon reading, replace it with the function pointer.