opera100

Suppose I have a ENUM T_MuxPos_type, where T_MuxPos_type{fixed;flexible;}. While I am coding, I have T_MuxPos_type Mux_pos. When Mux_pos = fixed, I have no problem with gcc but a compilation error with mvs2005:

c:\mvs2005\bs_module\source\config.cpp(1925) : error C2872: 'fixed' : ambiguous symbol
could be 'c:\panliu_bs\mvs2005\bs_module\source\declareenum.hpp(43) : T_MuxPos_type_E fixed'
or 'c:\program files\microsoft visual studio 8\vc\include\ios(183) : std::ios_base &std::fixed(std::ios_base &)'

If I solved this problem by Mux_pos = T_MuxPos_type::fixed, gcc compiler will complain about it. So what is the classic method to get rid of this ambigurity

I seems to me I should use namespace to solve it, but I don't name how to use it against ENUM.

Thanks!

opera100




Re: Visual C++ Language Function name conflict with ENUM name

Brian Kramer

You're not giving us complete information. Could you reduce your code to a few lines and post here



Re: Visual C++ Language Function name conflict with ENUM name

HCTwinJava

just use conditional compilation. for example,

#ifdef WIN32 //or any symbol you make to distinguish your compiler.

#else

#endif






Re: Visual C++ Language Function name conflict with ENUM name

Brian Kramer

It's better to understand the problem before writing two versions of code.



Re: Visual C++ Language Function name conflict with ENUM name

opera100

I was thinking that is the whole code. Let me try to explain it again.

1. I have a definition:

enum T_MuxPos_type

{

fixed;

flexible;

};

2. Somewhere in my code, I have:

T_MuxPos_type Mux_pos;

Mux_pos = fixed;

3. Then I have no problem with gcc but a compilation error with mvs2005:

c:\mvs2005\bs_module\source\config.cpp(1925) : error C2872: 'fixed' : ambiguous symbol
could be 'c:\panliu_bs\mvs2005\bs_module\source\declareenum.hpp(43) : T_MuxPos_type_E fixed'
or 'c:\program files\microsoft visual studio 8\vc\include\ios(183) : std::ios_base &std::fixed(std::ios_base &)'

4. If I solved this problem by Mux_pos = T_MuxPos_type::fixed, gcc compiler will complain about it. So what is the classic method to get rid of this ambigurity

5.I seems to me I should use namespace to solve it, but I don't name how to use it against ENUM.






Re: Visual C++ Language Function name conflict with ENUM name

opera100

The titie is a little misleading. I should say function name conflicts with ENUM value.




Re: Visual C++ Language Function name conflict with ENUM name

Brian Kramer

The following code does not compile under GCC 3.4.4, nor under EDG or VC8.  (But GCC doesn't give a very meaningful error.)  To summarize, your code needs to be corrected.  You can wrap your enumeration in a namespace or rename "fixed" to something else. 

#include <iostream>
using namespace std;

enum T_MuxPos_type
{
  fixed, flexible
};

int main()
{
  T_MuxPos_type Mux_pos = fixed;
  return 0;
}

For future reference, just post the minimal code (that compiles) needed for others to see the problem (rather than trying to characterize it in English).  Real code is worth a thousand words. :)

Brian

 





Re: Visual C++ Language Function name conflict with ENUM name

opera100

I understand what you are saying. Posting real code here will be absolutely helpful. However, I actually have a million lines and thousands of files, I cannot post a simple real code. I believe my question can be summarized by one english sentence:

What should I do if the name of an entry of an enum conflicts an existing file

I do not have the option to change "fixed" to other name, since I got thousands of them. Could you tell me how to wrap enumeration in a namespace I thought T_MuxPos_type Mux_pos = T_MuxPos_type::fixed does the same thing as namespace wrapping. However, I cannot pass gcc.

Thanks,






Re: Visual C++ Language Function name conflict with ENUM name

Brian Kramer

Standard C++, unfortunately, does not support qualifying the name of an enumerated value with its containing enumeration type. There is a Microsoft-specific compiler extension that allows you to do so anyway, but it is not portable. In fact VS2005 (VC8) reports: "warning C4482: nonstandard extension used: enum 'T_MuxPos_type' used in qualified name"

Here's my example, corrected to use a namespace.

#include <iostream>
using namespace std;

namespace my_namespace
{
enum T_MuxPos_type
{
fixed, flexible
};
}

int main()
{
my_namespace::T_MuxPos_type Mux_pos = my_namespace::fixed;
return 0;
}





Re: Visual C++ Language Function name conflict with ENUM name

opera100

Yes, this is a classic solution. I was expecting something like this. But this cannot solve my problem. So far, I don't think I can explain my problem by typing.

Anyway, I will credit this as answer.

Thanks!






Re: Visual C++ Language Function name conflict with ENUM name

Brian Kramer

It can solve your problem.  Before, you were prepared to qualify places where you used fixed as an enumerated value, so now you should be able to qualify using the new namespace.