correct use of enums?

I am getting an error
error: cannot initialize a variable of type 'Object::Type' with an rvalue of type 'int'
or
error: use of undeclared identifier 'OT_CIRCLE'


I have an object class which has some enums and I am trying to use these within another code. Here is some of the code.

Object.hpp
1
2
3
4
5
6
7
8
9
10
11

class Object {
public:
    enum Type {
        OT_CIRCLE,
        OT_SQUARE,
        OT_TRIANGLE,
        OT_INVALID
    };

//there is other stuff but im just showing the relevant parts 


Object.cpp
1
2
3
4
5
6
7
8
  #include "Object.hpp"

Object::Object(Type type) : objectType(type) {
}

Object::Type Object::type() const {
    return this->objectType;
}


Circle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#include Object.hpp

void Circle::doSomething(inputs){
Object::type() circle = OT_CIRCLE // THIS IS THE LINE THAT DOESNT WORK I get different errors depending on if I use OT_CIRCLE OR 2

/* if that line worked I would do something like
if ( object.type() != OT_CIRCLE) {
    do something
    }
else{
    do something else
    }
} */
Last edited on
Line 4 in Circle.cpp doesn't make sense. I guess that you mean:

Type circle = OT_CIRCLE;
Your assignment should be:
auto type = Object::OT_CIRCLE;

Example:
https://ideone.com/e6CIvq
Topic archived. No new replies allowed.