Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all.
I have an enum like that
C#
enum Dmode {
        select,
        place,
        place,
        text,
        paste 
};


I declared it as a new type, outside all my classes. When I built it in VC++ 2005, it's ok. But in VC++2010, the compiler reports that

SQL
error C2365: 'select' : redefinition; previous definition was 'function'
1>          c:\program files\microsoft sdks\windows\v7.0a\include\winsock2.h(1915) : see declaration of 'select'


same to 'connect'
My project has not any #include "winsock2.h" line.

If you have any solution, please give me.

Thank you so much!

Add: I tried changing name 'select' to 'select', the error was removed, but in my project has so many place I used 'select'. I don't want to change it :(
Posted
Updated 27-Aug-12 18:38pm
v4
Comments
Legor 28-Aug-12 4:41am    
"I tried changing name 'select' to 'select'"

How is this a change?
Minh Nguyen Ngoc 28-Aug-12 6:59am    
sorry for my mistake. I found in winsock2.h file, it has a function that named as 'select'. so I changed my enum item from 'select' to 'select1' or others... it's OK.

1 solution

Two things:
1. You may not have #included winsock2.h directly, but some other file you DID #include, included it in turn, either directly or indirectly through yet another #include. (A quick search on my system shows 21 files containing "winsock2.h" in the include directory.)
2. If you want to reuse names that conflict with system names, consider using namespaces[^]
Alternatively, you can use the Refactor/Rename command in VS to do an intelligent renaming of YOUR symbol.

Peter
 
Share this answer
 
Comments
Minh Nguyen Ngoc 28-Aug-12 7:06am    
Thanks for your solution. My friend also suggests me to use macro or namespaces but my project is so big and values of this enum are used at many places so I don't know how to change follow this suggestion.
Temporarily, I move this enum into the classes that use it. It seems OK.
But I hope find a better ideal.
Thank you
Legor 28-Aug-12 7:57am    
You should rather put all your classes in a common namespace. Your enum could be declared in a separate header file and in the same namespace as your classes. You can then #include the Header file with the enum in all files that use it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900