template <class type, int dim>
class Point
{
public:
Point();
Point(type coords[dim]){
for(int index = 0; index < dim; index++)
_coords[index] = coords[index];
}
type& operator[] (int index){
扫描二维码关注公众号,回复:
1482856 查看本文章
assert(index < dim && index >= 0);
return _coords[index];
}
type operator[] (int index) const
{ /* same as non-const instance */}
private:
type _coords[dim];
};
inline
template <class type, int dim>
ostream& operator<< (ostream &os, const Point<type, dim> &pt)
{
for(int ix = 0; ix < dim - 1; ix++)
os << pt[ix] << ",";
}