I want to implement hot code reloading in my program and it seems to work but I'm not sure if it is actually undefined behavior and I am just lucky.
I have a base class shared between a dll and the main program. The dll has a function that returns a pointer to the derived class
Base* getInstance(){return new Derived();}
When I reload the dll I also reload the getInstance function. Calling the virtual function from the base class still works but I think it might be undefined behavior. I'm not sure if I have to reload it. Also, it seems that if I load both instances of the dll and then free the old one instead of freeing the old one and loading the new one it breaks the vtable and crashes on calling the virtual function. How do virtual functions from a dll get loaded? Is my approach ok? What if I want to load at some point 2 instances of the dll.