I would like to build a simple application framework. The user is supposed to create a class derived from a base class and either use the properties and methods of the base class or override them with his own. Unfortunately, it is not at all clear to me how to instantiate a user class object from my framework library.
// library base class in appframework.hpp
class BasicApp
{
public:
// Initialisation
int initApp();
// Update is called from main loop
int Update();
// Handle input
int KeyInput(u32 KeysDown, u32 KeysHeld, u32 KeysDownRepeat, u32 KeysUp);
};
// user code
#include <appframework.hpp>
class AppMain: public BasicApp
{
// Handle input
int KeyInput(u32 KeysDown, u32 KeysHeld, u32 KeysDownRepeat, u32 KeysUp)
{
if (KeysDown & KEY_A) return 1;
return 0;
}
};
But how will my framework know about the AppMain class? The user should be able to override existing properties and methods and add their own that they can use but that the framework ignores.
I imagine it to be similar to a Java/Kotlin app in Android Studio:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// do whatever you want here
}
}
Are there any similar concepts in C++?
Thank you!