That should work, with a few conditions:
- If you intend to switch the definition of class B to something else, it won't work. The only thing you can change is the definition of foo().
- Both the plugin and the loading program must agree on the interface of class B on a binary level. Switching compilers (including version and some flags) can change this interface.
- You obviously have to cast the returnvalue of dlsym() in C++.
- Using classes in C is not possible.