tags:

views:

74

answers:

4

I have Visual studio 2005 . One of my header file has a enum like

typedef enum { scalar, array, set } increment;

When I try to include the header file I get an ambiguity error for "set". I am using the std::set in this cpp file . The issue is the compiler is unable to differentiate between the std::set and the set in the enum .

Any suggestions to resolve this ambiguity without declaring any new namespace

A: 

try prefixing your enum constant with something like "e"

enum E_increment { eScalar, eArray, eSet }

Eric
+6  A: 

Don't import the std namespace into the global namespace. The STL set is in the std namespace so if you don't have the line using namespace std in your headers you shouldn't get a conflict. Beyond that, refactor your enum.

Jherico
+1  A: 

If you've got using namespace std; in your file (or any headers it includes), that could be the problem.

guest
A: 

The usual solution to this problem in C++ is to use more descriptive value names. For example, look at the Qt enum GestureType. Its values are named like TapGesture and PanGesture, rather than just "Tap" and "Pan". In your case I suggest:

enum increment { scalar_increment, array_increment, set_increment };

In the next revision of C++ there will be a proper solution in the form of strong enums.

Stefan Monov
-1........ Why?
Stefan Monov