How should I call a method within a defined class from a template class method?
Below is my scenario –
-
Template Class
template <class T> class TC { void myTemplateMethod() { T.myMethod(); //can I call like this ? } }; -
Defined Class
class tdef { void myMethod() { //does something } }; -
Main
int main() { TC<tdef> tobj; tobj.myTemplateMethod(); //can I call tdef.myMethod() like this? }
Just to note, that I have debugged a code like this and have found that tdef.myMethod() does not work when called like this. Also are there any chances that some exceptions are not handled while calling tdef.myMethod() from within Template class method?
-Somnath
That’s a non-static member function, so it can only be called on an instance. Templates don’t change that fact.
or if the function were static: