To Oluseyi: I meant the addition of two 3d vectors might use the 2d vector addition, not a 2d and a 3d.
Say my file ("kvector.h") looks like this.
----------------------------
// Same as above post
2d Template Definition (kv2)
2d Operators
3d Template Definition (kv3)
3d Operators
4d Template Definition (kv4)
4d Operators
----------------------------
The code for the 2d addition (see above post) would have no trouble attaching itself to the 3d vector template, because the template argument for the 2d addition operator is "class A", not "kv2 a".
Example:
main() { v3i32 a = v3i32( 1, 2, 3); v3i32 b = v3i32( 4, 5, 6); v3i32 c = a + b;}
Line 3 might use the 2d addition operator instead of the 3d addition operator. In this case:
c.x = a.x + b.x;
c.y = a.y + b.y;
c.z = a.z; (incorrect)
My question basically boils down to: How do I restrict the scope of my operator templates so that "class A" only ever substitutes a kv2 (where kv2 is a templated struct). Do I place the operator inside the kv2 template definition, or outside it, and either way, what is the correct syntax.
BTW, is this beginner-level templates (ie, I''m in the wrong forum)?