I know that you can get a reference to a static method like this:
typedef void (*pointer)();
pointer p = &MyClass::MyMethod;
But is there a way to get a reference to the class itself?
EDIT:
I’d like to store a class name to a variable so i could instantiate different kinds of objects based on the current value of the variable to a buffer or a list. I could then perform operations on the list of objects (using polymorphism).
No, “the class itself” is not an object that exists at runtime in C++ — it’s a compile-time concept only. Therefore you cannot get a reference or pointer to “a class object” per se, only to instances, functions (including static ones), and so on — things that do exist at runtime.
With RTTI you can get somewhat-similar effects, though — the typeid keyword gives you a reference to a
std::type_info(you need to#include <typeinfo>to enable this) which “stands for” the type in question at runtime. (You may also need special compiler switches to enable this functionality, e.g./GRfor Microsoft’s Visual C++).Whether that’s good enough for you depends on exactly what it is that you’re trying to accomplish. Care to clarify?