2

尝试构建项目时出现此错误:

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"'

我已经对其进行了一些研究,看起来我有一个错误的方法头,但我是 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;
}
4

1 回答 1

2

我的猜测是问题出在度数符号上,它不是 ascii 字符。

请尝试:

wcout <<  getDegrees() << L"\u00B0";
于 2012-07-17T13:12:42.010 回答