Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-10-27 04:26:10


Rani Sharoni wrote:
> According to 14.6.5/2 comment 131:
> Friend declarations *do not introduce new names* into any
> scope, either when the template is declared or when it is
> instantiated.

Actually, the example that follows that very paragraph demonstrates how one
can use argument dependent lookup to override the rule
('instantiation_count' does the same):

    template<typename T> class number {
        number(int);
        //...
        friend number gcd(number& x, number& y) { /* ... */ }
        //...
    };

    void g()
    {
        number<double> a(3), b(4);
        //...
        a = gcd(a,b); // finds gcd because number<double> is an
                        // associated class, making gcd visible
                        // in its namespace (global scope)
        b = gcd(3,4); // ill-formed; gcd is not visible
    }

>
> I hope that I and EDG are wrong.

At least in this regard, yes, you are :).

Aleksey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk