|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2004-02-20 17:33:19
Brian McNamara <lorgon_at_[hidden]> 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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk