0

我收到标题中所述的错误消息。我正在尝试构建一个继承了 Shape 类的 Line 类。我在

Shape(color) {}

在行构造函数中执行。

头文件(形状和线条在一个,颜色在另一个)

形状.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

图片.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){
}
4

2 回答 2

0

structColor必须在用作 的成员之前声明Shape

于 2013-04-23T21:19:00.307 回答
0

似乎从 Line 类的 Draw 声明中收回“void”是有效的。由于某些原因

于 2013-04-25T16:29:40.887 回答