mardi 23 octobre 2018

Multiple definition of enum class 'classname'

The error I get is .

error: multiple definition of 'enum class Color'

I searched the internet (including here) but I couldn't find a solution. I tried lots of things like deleting the namespaces in header files(still deleted) or putting extern before color(gived error).The only thing seem to work was including everything in the ComposedShape file and including ComposedShape.h in every file but then the classes conflicted somehow.But the thing I know is the header guards should be preventing this so I wrote this version of the code. My files are like this.

--Circle.h--
#ifndef _HW2_CIRCLE_H
#define _HW2_CIRCLE_H
enum class Color{G,R};

...
#endif

--Triangle.h--
#ifndef _HW2_TRI_H
#define _HW2_TRI_H
enum class Color{G,R};

...
#endif

--Rectangle.h--
#ifndef _HW2_RECT_H
#define _HW2_RECT_H
enum class Color{G,R};
...
#endif

--ComposedShapes.h--
#ifndef _HW2_CS_H
#define _HW2_CS_H

...
#endif

--main.cpp--
#inlude "ComposedShapes.h"

and the cpp files for all of them it gives the error

Aucun commentaire:

Enregistrer un commentaire