我是cpp的新手,并试图在没有运气的情况下解决问题谷歌,可以使用帮助。
哦,我的文件都在同一个文件夹中。
Rectangle.h文件:
#ifndef RECTANGLE_H_
#define RECTANGLE_H_
#include "Polygon.h"
class Rectangle: public Polygon{
public:
Rectangle(int nColor);
Rectangle(Rectangle& r);
virtual string getType();
int getArea();
};
#endif /* RECTANGLE_H_ */
错误在这里,在每个方法签名下它是sais: “首先在这里定义”
Rectangle.cpp文件:
#include "Rectangle.h"
#include "Polygon.h"
//error is - "first defined here"
Rectangle::Rectangle(int color):Polygon(color, 3, "Rectangle"){
}
//error is - "first defined here"
Rectangle::Rectangle(Rectangle& r) :
Polygon(r) {
}
//error is - "first defined here"
string Rectangle::getType() {
return "Rectangle";
}
//error is - "first defined here"
int Rectangle::getArea() {
return 0;
}
我也在添加父类“Polygon.h”,但我很确定它不相关...... 唯一有趣的是方法:
Polygon h:
#ifndef __POLYGON_H
#define __POLYGON_H
#include "Point.h"
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Polygon {
public:
Polygon(int nColor , int nPoints , std::string type);
Polygon(const Polygon &polyOther);
virtual ~Polygon() = 0;
int getColor();
virtual string getType();
void addPoint(Point* p);
Point* getPoint(int index) const;
int getNumOfPoints() const;
Polygon& operator=(const Polygon &polyOther);
private:
std::vector<Point*> _points;
const int _color;
string _type;
};
#endif
感谢您的帮助......