我收到標題中指出的錯誤消息。我試圖構造一個繼承Shape類的類Line。在行構造函數中執行構造函數中的「對行中的vtable引用未定義」
Shape(color) {}
錯誤。
頭文件(形狀和線條於一身,顏色不同)
Shape.h:
#ifndef SHAPE
#define SHAPE
#include "Image.h"
class Shape{
private:
Color color;
public:
Shape (const Color & col) : color(col){}
virtual void Draw(Image & figure) const = 0;
};
class Line : public Shape{
public:
Line (int x1, int y1, int x2, int y2, const Color & color);
virtual void Draw(Image & figure) const;
private:
int x1, y1, x2, y2;
};
#endif // SHAPE
image.h的:
struct Color {
Color(unsigned char r, unsigned char g, unsigned char b)
: red(r), green(g), blue(b) {
}
Color() : red(0), green(0), blue(0) {
}
unsigned char red, green, blue;
};
這裏是Shape.cpp
#include "Shape.h"
Line::Line(int x1, int y1, int x2, int y2, const Color &color)
: x1(x1)
, x2(x2)
, y1(y1)
, y2(y2)
, Shape(color){
}
也許添加顏色(顏色&)構造函數結構顏色? – 2013-04-23 21:15:26
那也行不通 – user1784297 2013-04-23 21:33:43