我收到标题中指出的错误消息。我试图构造一个继承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