Is it possible to pass a class as a function parameter in C ++?

I have a function with void * as one of its parameters (void is used as a shared object). But in order to be able to call a function in this universal object, I need to sketch it first, and for this I need to know what type of class is. And I wanted to know if it is possible to pass a class or some information that allows me to display an object as a function parameter?

+7
source share
1 answer

If you looked at Templates ?

An example would be something like

class SomeClass { public: template<typename CastClass> void DoSomething(void* someArg) { (CastClass)someArg; } }; 

Using:

 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. 
+9
source

All Articles