Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
41 Views

enum namespace conflict

C++ from Parallel Studio XE 2017 Cluster Edition, Windows 7

enum StiffnessModel
{
    Seed = 1,
    Chord = 2
};

Produces namespace collision with

C:\Program Files (x86)\Windows Kits\8.1\Include\um\wingdi.h(3615): error : "Chord" has already been declared in the current scope
1>     WINGDIAPI BOOL  WINAPI Chord( _In_ HDC hdc, _In_ int x1, _In_ int y1, _In_ int x2, _In_ int y2, _In_ int x3, _In_ int y3, _In_ int x4, _In_ int y4);

My work around is to change the name in the enum (Chord_sm).

Jim Dempsey

0 Kudos
5 Replies
Highlighted
41 Views

Note, using C++ from Parallel Studio XE 2017 Cluster Edition, Linux produces no err (due to no wingdi.h).

Minor annoyance.

Jim Dempsey

0 Kudos
Highlighted
Employee
41 Views

 

The Intel compiler just uses the Windows headers on the system so I don't think we can do anything about namespace pollution from the Microsoft supplied headers. Microsoft gives a similar error so this is not a compiler bug.

!% cat foo.cpp

#include <windows.h>

enum StiffnessModel
{
    Seed = 1,
    Chord = 2
};

!% cl -c foo.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

foo.cpp
foo.cpp(8): error C2365: 'Chord': redefinition; previous definition was 'functio
n'
//hrcna01a.nh.intel.com/wref1/ref/vs2015u3/Windows Kits/10/include/10.0.10586.0/
um\wingdi.h(3676): note: see declaration of 'Chord'
!%

0 Kudos
Highlighted
41 Views

The following comment (opinion) may be more of a C++ language thing...

Due to the fact that the C++ compiler can understand:

    StifnessModel::Chord

IOW in the scope of the enum StiffnessModel...

And that the compiler can disambiguate between different signature functions, say Chord with different arguments...

... given the fact (additional information) that the statement in question scoped the enum:

if (layer.materialType == MaterialType::unbound && layer.unbound.stiffModel == StiffnessModel::Chord)

The explicit scoping should have removed any ambiguity as to what to reference.

Jim Dempsey

0 Kudos
Highlighted
Employee
41 Views

 

If you want the enumerator names to be hidden then you can use the c++11 scoped enum feature, i.e. this compiles fine (notice the class keyword after enum):

enum class StiffnessModel
{
    Seed = 1,
    Chord = 2
};

http://stackoverflow.com/questions/18335861/why-is-enum-class-preferred-over-plain-enum

Judy

0 Kudos
Highlighted
41 Views

Thanks Judy.

Jim Dempsey

0 Kudos