---
# System prepended metadata

title: 重載運算符
tags: [C++Book]

---

# 重載運算符
###### tags: `C++Book`

```cpp
 class CVector {
 public:
	 int x,y;
	 CVector () {};
	 CVector (int,int);
	 CVector operator + (CVector);
 };

 CVector::CVector (int a, int b) {
	 x = a;
	 y = b;
 }

 CVector CVector::operator+ (CVector param) {
	 CVector temp;
	 temp.x = x + param.x;
	 temp.y = y + param.y;
	 return (temp);
 }
```

可被重載的運算符
```
+ - * / = < > += -= *= /= << >>
<<= >>= == != <= >= ++ -- % & ^ ! |
~ &= ^= |= && || %= [] () new delete
```