I am converting an MFC appl开发者_开发百科ication for deadlock detection in to Simple console application. During this process I found many errors saying like
error C2365: 'CmdLockMutex' : redefinition; previous definition was 'enumerator'
I am unable to remove this error. Kindly if someone could help me in this regard.
Ok 4 years later to OP here is your answer...
The Problem: With unscoped enums, you can have this situation:
enum Suit { Diamonds, Hearts, Clubs, Spades };
enum Tools { Picks, Shovels, Spades, Hammers }; // error C2365: 'Spades' :
// redefinition; previous definition was 'enumerator'
The Solution:
Scoped enums solve this problem:
enum class Suit { Diamonds, Hearts, Clubs, Spades };
enum class Tools { Picks, Shovels, Spades, Hammers };
Source: MSDN
Use of the keyword class or struct in the enum definition indicates that each enum type is unique and not comparable to other enum types. In addition to this advantage, you can also forward-declare them without specifying an underlying type (as you do with unscoped enums if you intend to forward-declare).
Sounds like you need a header guard around your definition of CmdLockMutex
(Add #pragma once
at the top of its .h file.). Or rather you have a naming conflict.
Maybe you have something like this:
enum MyEnum { MyEnumVal1, MyEnumVal2 };
//....
class MyEnum
{
};
I've had an issue like this where some code definitions were placed in a header file. The header was included in two places, and so conflicted with itself. My solution was to move them to their own cpp file. You might be seeing something like this.
Another cause can be failing to use a #pragma once or wrap with the #ifndef technique in a header.
The obvious answer is that you have prevously used the name CmdLockMutex
- probably in an enum
. Search your code for all occurnces of "CmdLockMutex"
精彩评论