
Brian McNamara <lorgon@cc.gatech.edu> writes:
On Fri, Feb 20, 2004 at 04:03:57PM -0500, David Abrahams wrote:
Simple: specializations that follow the point of instantiation aren't considered. This program exits with an error:
template <class T> int f(T) { return 1; }
int main() { return ::f(0); }
template <> int f(int) { return 0; }
Aha; this is part of what I was missing. This clears most of it up for me.
One last question, and then I think I'm done. In my example:
namespace lib { template <class T> void f(T) { /* print "bar" */ } template <class T> void g(T x) { lib::f(x); } // (1) }
namespace user { struct MyClass {}; } namespace lib { template <> void f( user::MyClass ) { /* print "foo" */ } }
int main() { user::MyClass m; lib::g(m); // (2) }
What is printed?
foo
(I think this question comes down to whether or not (1) or (2) is the "point of instantiation" of f(), yes?)
Yeah; if you change g so it callse lib::f(0) it prints bar. -- Dave Abrahams Boost Consulting www.boost-consulting.com