Compiling SymbolicC++ - operator , is ambiguous

雨燕双飞 提交于 2020-01-04 06:30:50

问题


I'm trying to compile the SymbolicC++ library in VC++ 2010 Express (there is special VS project in the distribution), but it gives a lot of errors in system headers, related to operator,. For example:

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xlocmon(410): error C2593: 'operator ,' is ambiguous

For this code in a system header:

if (_Str[0] < _E0 || _E0 + 9 < _Str[0])
    _Str2 += '-', ++_Off;

Why? How to compile it?


回答1:


Apparently, SymbolicC++ has overloaded operator, in such a manner that a downstream include has been affected.

You should reorder your includes such that SymbolicC++'s include comes last:

#include <iostream>
#include <vector>

// don't want to monkey with our other headers
#include "symbolicc++.h"

This isn't to say the code in the <xlocmon> header isn't suspect, that sort of abuseusage of the comma operator is asking for trouble.




回答2:


When in doubt, add parentheses:

    if (_Str[0] < _E0 || _E0 + 9 < _Str[0])
        (_Str2 += '-'), ++_Off;

Or simply write proper C++ code:

    if (_Str[0] < _E0 || _E0 + 9 < _Str[0])
    {
        _Str2 += '-';
        ++_Off;
    }



回答3:


Here's another workaround which avoids having to modify <xlocmon>.

The dependency on <xlocmon> is via verylong.h which includes <iomanip> which in turn includes <xlocmon>. In verylong.h, comment out the line:

#include <iomanip>

After doing this, the build completes successfully on my system (Windows 7, Visual C++ 2010 Express).




回答4:


We have no idea what their operator, is doing, so this may well not be valid, but that's a weird way to do things -- the following is equivalent and less weird:

    if (_Str[0] < _E0 || _E0 + 9 < _Str[0]) {
        _Str2 += '-';
        ++_Off;
    }



回答5:


The comma operator doesn't make any sense in 90% of the cases. The solution is to hit whoever wrote that code in the head with a blunt object, then rewrite it as:

if (_Str[0] < _E0 || _E0 + 9 < _Str[0])
{
  _Off++;
  _Str2 += '-';
}


来源:https://stackoverflow.com/questions/9619774/compiling-symbolicc-operator-is-ambiguous

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!