当我尝试构建项目时遇到此错误:
Angle.cpp:466: error: ambiguous overload for 'operator<<' in '(+out)-
>std::basic_ostream<_Elem, _Traits>::operator<< [with _Elem = char,
_Traits = std::char_traits<char>](((const Angle*)this)->Angle::getDegrees())
<< "\37777777660"'
我对此进行了一些研究,看起来我有一个错误的方法 header ,但我是 cpp 新手,不知道如何修复此错误。
这是 .h:
#include "OutputOps.h"
// End user added include file section
#include <vxWorks.h>
#include <ostream>
class Angle {
public:
// Default constructor/destructor
~Angle();
// User-defined methods
//
// Default Constructor sets Angle to 0.
Angle();
...
// Returns the value of this Angle in degrees.
double getDegrees() const;
....
// Prints the angle to the output stream as "x°" in degrees
void output(std::ostream& out) const;
...
private:
...
double radians;
static const double DEGREES_PER_RADIAN /* = 180.0 / PI */;
};
#endif // ANGLE_H
方法如下:
#include "MathUtility.h"
#include <cmath>
// End user added include file section
#ifndef Angle_H
#include "Angle.h"
#endif
//
// Prints the angle to the output stream as "x°" in degrees
void Angle::output(std::ostream& out) const
{
out << getDegrees() << "°";
}
//
// Returns the value of this Angle in degrees.
double Angle::getDegrees() const
{
return radians * DEGREES_PER_RADIAN;
}
最佳答案
我的猜测是问题出在度数符号上,它不是一个 ascii 字符。
尝试一下:
wcout << getDegrees() << L"\u00B0";
关于c++ - 错误: ambiguous overload for 'operator<<' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11522865/