I have a function with void * as one of its parameters (the void is used as a generic object). But to be able to call a function in that generic object, I need to cast it first, and for that I need to know what type the class is. And I wanted to know, is it possible to pass a class or some information that allows me to cast the object as a function parameter?
By any chance have you looked into Templates?
An example would be something such as
class SomeClass
{
public:
template<typename CastClass>
void DoSomething(void* someArg)
{
(CastClass)someArg;
}
};
Usage:
class A{ }; // Some random test class
SomeClass test;
A a;
test.DoSomething<int>(&a); // The template parameter can be anything.
// I just have int to make it a smaller example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With