2013-04-23 173 views
0

我收到標題中指出的錯誤消息。我試圖構造一個繼承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){ 
} 
+0

也許添加顏色(顏色&)構造函數結構顏色? – 2013-04-23 21:15:26

+0

那也行不通 – user1784297 2013-04-23 21:33:43

回答

0

struct Color必須在被用作Shape的成員之前聲明。

+0

你會怎麼做這樣的事情? – user1784297 2013-04-23 21:21:56

+0

通過將'顏色'[上面形狀](http://coliru.stacked-crooked.com/view?id=cda018b999e446bb39a1f208ca095ba4-50d9cfc8a1d205ca7409e81e87c2653ba) – alexrider 2013-04-23 21:23:59

+0

但顏色是在「Image.h」。 「Image.h」包含在「Shape.h」中。這不夠嗎? – user1784297 2013-04-23 21:25:33

0

似乎從Line類的Draw聲明中收回了「void」。由於某種原因

相關問題