templates - How to refer to a doubly-templated free function in C++ -


i have templated class within define free functions taking references templated class. these free functions templated on different parameter.

from outside class can call free functions. however, cannot find correct syntax 1 free function call another.

quick example:

template<typename t> class foo {   template<typename s>   friend s f(const foo &) { return s(); }    template<typename s>   friend s g(const foo &s) {     return f(s);  // see below, when instantiated, yields 'no matching function call f(const foo &)'   } };  float test1() {   foo<int> o;   return f<float>(o); // compiles }  float test2() {   foo<int> o;   return g<float>(o); // fails compile line above errors } 

(c.f. this link too)

it seems point of call f(s) within g(), outermost template has been lost. how might re-specify t in call f? have checked on gcc4.7, 4.8, clang 3.2 equivalent errors.

when call f(s) need specify template parameter s because can't deduced argument s.

but if change f<s>(s) (assuming meant call same template argument s g called with) inhibit adl, , way friend function defined @ class scope can found adl. need add declaration of f global namespace, call in g can find it.

so make work need add these declarations before foo

template<typename t> class foo;  template<typename s, typename t>   s f(const foo<t> &);  template<typename s, typename t>   s g(const foo<t> &); 

and change call in g f<s>(s) or else f<x>(s)


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -