Can i do something like:
Code:class T { void doIt(SomeClass) { //call some static method on SomeClass } }; int main() { T a; //Pass ref to the class itself, rather than an instance a.doIt( ::SomeClass ); }
Can i do something like:
Code:class T { void doIt(SomeClass) { //call some static method on SomeClass } }; int main() { T a; //Pass ref to the class itself, rather than an instance a.doIt( ::SomeClass ); }
correct me if I am wrong, but, no, it's not javascript. (the compiler needs to know exactly which function to call in doIt(), which is not possible if it doesn't know what class is going to be passed in)
Code:class Someclass { static void method() {}; }; class T { void doIt(SomeClass &c) { //call some static method on SomeClass c.method(); } }; int main() { Someclass d; T a; //Pass ref to the class itself, rather than an instance a.doIt( d ); }
Last edited by robwhit; 05-01-2008 at 04:25 PM. Reason: all-important typo :D
Although in this case, class T is redundant, as this could be implemented as a free function.Code:class T { template <typename C> void doIt() { C::someMethod(); } }; T().doIt<SomeClass>();
sorry, typo.
1) Use a simple wrapper and a constant reference to that wrapper. (A class instance would not be passed, only an instance of the wrapper--which need not have a reference to the class itself.)
2) Use a template method and explicitly pass arguments to the template parameters.
3) Use a pointer-to-a-function and pass the static method directly.
4) "Erase" the target function type with something like "functiods" and pass an instance of that object.
Soma