Есть 2 класса:
1-й:
Код:
//polygon.h
#ifndef polygon_h
#define polygon_h
#include "coordinate.h"
class polygon
{
public:
polygon();
polygon(unsigned amount,coordinate x_temp, coordinate y_temp);
virtual ~polygon();
bool square(double& s);
friend std::istream& operator>>(std::istream& is,polygon& object);
protected:
virtual bool isEnter() const;
virtual double calculationSquare();
private:
void centroid(double& x_central,double& y_central) const;
void sorting(double x_int,double y_int);
void polar_coordinate(coordinate& z,double x_int,double y_int) const;
double squareTriangle(double x1,double y1,double x2,double y2,double x3,double y3) const;
private:
coordinate x;
coordinate y;
unsigned number;
bool isEnterVar;
};
inline polygon::polygon()
{
isEnterVar=false;
}
inline bool polygon::isEnter() const
{
return isEnterVar;
}
inline polygon::~polygon()
{
}
#endif
Код:
//polygon.cpp
#include "polygon.h"
#include <iostream>
#include <math.h>
using namespace std;
//....
std::istream& operator>>(std::istream& is,polygon& object)
{
is >> object.number;
object.x.resize(object.number);
object.y.resize(object.number);
for(unsigned i=0;i<object.number;++i)
{
is >> object.x[i] >> object.y[i];
}
object.isEnterVar=true;
return is;
}
//....
2-й:
Код:
//rectangle.h
#ifndef rectangle_h
#define rectangle_h
#include "coordinate.h"
#include "polygon.h"
class rectangle: public polygon
{
public:
rectangle();
rectangle(coordinate x_temp,coordinate y_temp);
friend std::istream& operator>>(std::istream& is,rectangle& object);
~rectangle();
private:
bool isEnter() const;
double calculationSquare();
void MaxMinCoordinate(double& x_max,double& y_max,double& x_min,double& y_min) const;
private:
coordinate x;
coordinate y;
bool isEnterVar;
};
inline rectangle::rectangle():polygon()
{
isEnterVar=false;
}
inline bool rectangle::isEnter() const
{
return isEnterVar;
}
inline rectangle::~rectangle()
{
}
#endif
Код:
//rectangle.cpp
#include "rectangle.h"
#include <math.h>
//...
std::istream& operator>>(std::istream& is,rectangle& object)
{
object.x.resize(2);
object.y.resize(2);
for(unsigned i=0;i<2;++i)
{
is >> object.x[i] >> object.y[i]; //здесь ругается!
}
object.isEnterVar=true;
return is;
}
//...
Перегружаю оператор >>. Для 1-го класса не ругается, а для 2-го ругается: ошибка: no match for ‘operator>>’ in ‘is >> object->rectangle::x.std::vector<_Tp, _Alloc>::operator[] [with _Tp = double, _Alloc = std::allocator<double>](i)’
Вот вектор:
Код:
//coordinate.h
#ifndef coordinate_h
#define coordinate_h
#include <vector>
typedef std::vector<double> coordinate;
#endif
Никак не пойму ошибку