Topic: Koenig lookup and template function pointers


Author: loewis@informatik.hu-berlin.de (Martin v. Loewis)
Date: 1998/06/30
Raw View
Is the following program correct?

namespace N{
  struct S{};
  typedef void (*Sfunc)(S&);
  void f(Sfunc){}
}

template<class T>
void g(T&)
{}

main()
{
  f(g);
}

Probably not. If not, why not? I assume that passing templates in such
a way is legal. At least, [over.over]/1 specifies that a function
template names a set of functions if used as a parameter of a
function.

If so, what is the type of g as mentioned in [basic.lookup.koenig]/1?
[over.over]/2 requires to perform template argument deduction, which
requires to know the target type. For that, I need to do overload
resolution, and therefore lookup of f. In order to do that, I need to
determine the types of all arguments of f, for which I need to do
template argument deduction first.

Any comments? If the above is wrong, would f(g<N::S>) be a legal call?

TIA,
Martin


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]