I have the following class structure
// shape.h
enum colors {RED=0, BLUE, GREEN};
class Shape {
public:
colors col;
void setColor(colors c) {
col = c;
}
};
// circle.h
#include "Shape.h"
class Circle: public Shape {};
// rect.h
#include "Shape.h"
class Rect: public Shape {};
In my main.cpp
I include both, Circle
and Rect
.
#include <iostream>
#include "Rect.h"
#include "Circle.h"
int main() {
return 0;
}
Unfortunately, this leads to an error: error: multiple definition of 'enum colors'
, because they are both inheriting from Shape
. I am new to C++ and wonder what is the best practice to avoid/solve this?