1

I have this enum in Item class

 enum EquipSlot
{
RightHand,
Head,
...
};

character class has this function declaration

void Character::UnequipSlot(Item::EquipSlot slot);

item class is not in any namespace or a part of another class.

i use Item::EquipSlot in implementation a lot with no error. it only gives compile error while in declaration.

What's the correct way to call enum of another class?

(compiler is vc++ 9) error is : error C2027: use of undefined type 'Item' (item class is used in other declarations)

thanks.

2
  • 2
    I have no idea what exactly you you ask for? Maybe showing us the compiler error would help. So would showing us what exactly you did to get that error and how you used Item::EquipSlot not giving you an error. Basically your question needs more information to be answerable Commented Jan 12, 2012 at 17:40
  • You might try to convince yourself what's going on by writing the smallest, complete program covering your issue, which then either compiles or fails to compile. Too much ambiguity about your environment here. Commented Jan 12, 2012 at 17:58

1 Answer 1

2

Include the header that defines Item.

If Item is only declared, Item may be used in some contexts, but not when the size or contents of Item are required.

Sign up to request clarification or add additional context in comments.

2 Comments

i'm using precompiled headers. it was using forward declaration of item class but wasn't enough(why?). now i changed order of character.h and item.h. it worked. it seem forward declaration does not give information enough to use enums.
@mikbal: That's correct. A forward declaration only assures the compiler that the class exists. You'll see from the other uses of Item in that file that no other information about Item was needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.