# BOO大全/值型别

### 值型别

```struct Point3D:
public X as double
public Y as double
public Z as double

def constructor(x as double, y as double, z as double):
X = x;  Y = y;   Z = z

def Add(p as Point3D):
return Point3D(X + p.X, Y + p.Y, Z + p.Z)

override def ToString():
return "(\${X},\${Y},\${Z})"

p1 = Point3D(10.0,20.0,30.0)
p2 = Point3D(1.0,1.0,2.0)
print p1,p2,p1.Add(p2)
```

```(10,20,30) (1,1,2) (11,21,32)
```

#### 运算子的覆载

```	static def op_Addition(self as Point3D, p as Point3D):
return Point3D(self.X + p.X, self.Y + p.Y, self.Z + p.Z)
```

• op_Addition +
• op_Subtraction -
• op_Multiply *
• op_Division /
• op_Modulus %
• op_Exponentiation **
• op_Equality ==
• op_LessThan <
• op_LessThanOrEqual <=
• op_GreaterThan >
• op_GreaterThanOrEqual >=
• op_Match =~
• op_NotMatch not =~
• op_Member in
• op_NotMember not in
• op_BitwiseOr |
• op_BitwiseAnd &
• op_UnaryNegation -

##### OverloadInPlaceAddition

It would probably be useful to allow binary operations like InPlaceAddition to be overloaded directly, because just relying on the usual x += y ==> x = x + y leads to potentially inefficient code for value types.

The question is, why restrict overloading at all?