1. 数组运算符重载,以及异常抛出
(1)一个是const类型重载,只返回元素值,不能修改
(2)一个是非const类型重载,返回元素值,并且可直接操作修改
分别应用于const vector2对象,或vector2对象
double operator[] (int i) const { if((i < 0)||(i > 1)) throw std::runtime_error("Out of bounds in Vector2::operator[]") ; return _xyz[i]; } double& operator[] (int i) { if((i < 0)||(i > 1)) throw std::runtime_error("Out of bounds in Vector2::operator[]") ; return _xyz[i]; }
2.
3.
4.
5.
endl;
浙公网安备 33010602011771号