Timeline for C++ to friend or not to friend
Current License: CC BY-SA 3.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 26, 2015 at 14:29 | comment | added | MSalters | That's pretty theoretical. Perhaps the only common non-commutative case would be inline Vector operator*(double a, Vector v) { return -v*a; } and that still doesn't require friendship. | |
| Jul 26, 2015 at 7:39 | comment | added | Emilio Garavaglia | @MSalters: That's valid only if * is commutative respect to a and v(x). If the vector components are generic (not necessarily scalars) you have to keep the operand order | |
| Sep 8, 2011 at 16:03 | vote | accept | nikhil | ||
| Sep 5, 2011 at 19:11 | comment | added | kevin cline | @MSalters: Good point. I picked a poor example. I think your inline function is a free function by definition, but no friend declaration is required. | |
| Sep 5, 2011 at 12:31 | comment | added | MSalters | "This requires a free function". No, it doesn't: inline Vector operator*(double a, Vector v) { return v*a; }. Canonical solution in fact. | |
| Sep 4, 2011 at 20:58 | history | edited | kevin cline | CC BY-SA 3.0 | fix formatting |
| Sep 4, 2011 at 19:16 | history | edited | kevin cline | CC BY-SA 3.0 | added 2 characters in body |
| Sep 4, 2011 at 18:29 | history | answered | kevin cline | CC BY-SA 3.0 |