I'm trying to overload the << operator. I have a point class which is represented by a vector of doubles. In this class I have overloaded the << operator with no problem:
Expand|Select|Wrap|Line Numbers
- class Point
- {
- public:
- //constructor
- Point();
- Point(vector<double> v);
- }
- Point::Point()
- {
- vector<double> vec(4,0);
- vec[3]= 1;
- point = vec;
- size = vec.size();
- }
Expand|Select|Wrap|Line Numbers
- ostream& operator<<(ostream& os, const Point& p)
- {
- int sz = p.get_size();
- os << "(";
- for (int i=0; i<sz; i++) {
- os << p.get_val(i) << " ";
- }
- os << ")" << endl;
- return os;
- }
Expand|Select|Wrap|Line Numbers
- fourpoints::fourpoints()
- {
- Point p1;
- Point p2;
- Point p3;
- Point p4;
- }
Expand|Select|Wrap|Line Numbers
- ostream& operator<<(ostream& os, const fourpoints& p)
- {
- os << "1. point: " << p.get_1();
- return os;
- }
Expand|Select|Wrap|Line Numbers
- Point fourpoint::get_1() const
- {
- return this->p1;
- }