Created on 2002-10-27.00:00:00 last changed 207 months ago
[Voted into WP at March 2004 meeting.]
Proposed resolution (April 2003):
Replace the example in _N4868_.13.8.6 [temp.inject] paragraph 2
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
}
by
template<typename T> class number {
public:
number(int);
//...
friend number gcd(number x, number y) { return 0; }
private:
//...
};
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
}
Drafting note: Added "return" to the friend function, removed references in gcd arguments, added access specifiers.
The example in _N4868_.13.8.6 [temp.inject] paragraph 2 is incorrect:
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
}
Regardless of the last statement ("b = gcd(3,4);"), the above code is ill-formed:
a) number's constructor is private;
b) the definition of (non-void) friend 'gcd' function does not contain a return statement.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2008-10-05 00:00:00 | admin | set | status: wp -> cd1 |
| 2004-04-09 00:00:00 | admin | set | messages: + msg1025 |
| 2004-04-09 00:00:00 | admin | set | status: ready -> wp |
| 2003-11-15 00:00:00 | admin | set | status: review -> ready |
| 2003-04-25 00:00:00 | admin | set | messages: + msg833 |
| 2003-04-25 00:00:00 | admin | set | status: open -> review |
| 2002-10-27 00:00:00 | admin | create | |