c++ - templated method on T inside a templated class on TT : Is that possible/correct -


i have class myclass templated on typename t. inside, want method templated on type tt (which unrelated t).

after reading/tinkering, found following notation:

template <typename t> class myclass {    public :       template<typename tt>       void mymethod(const tt & param) ; } ; 

for stylistic reasons (i have templated class declaration in 1 header file, , method definitions in header file), won't define method inside class declaration. so, have write as:

template <typename t>     // type of class template <typename tt>    // type of method void myclass<t>::mymethod(const tt & param) {    // etc. } 

i knew had "declare" typenames used in method, didn't know how exactly, , found through trials , errors.

the code above compiles on visual c++ 2008, but: is correct way have method templated on tt inside class templated on t?

as bonus: there hidden problems/surprises/constraints behind kind of code? (i guess specializations can quite amusing write)

this indeed correct way of doing want do, , work on every decent c++ compiler. tested on gcc4.4 , latest clang release.

there problems/surprises/constraints behind kind of code.

the major issue run in code can't make templated function virtual, if want polymorphism @ class level templated function, you're off implementing external function.


Comments

Popular posts from this blog

Delphi Wmi Query on a Remote Machine -