0

I'm getting the error message stated in the title. I'm trying to construct a class Line which has inherited the class Shape. I get an error in the

Shape(color) {}

execution in the line constructor.

Header files (Shape and Line in one, Color in another)

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;
};

And here is the 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){
}
awesoon
  • 32,469
  • 11
  • 74
  • 99
user1784297
  • 103
  • 12

2 Answers2

0

struct Color must be declared prior to being used as a member of Shape.

alexrider
  • 4,449
  • 1
  • 17
  • 27
0

It appears that retracting "void" from the Draw declaration in the Line class worked. For some reason

user1784297
  • 103
  • 12