错误:'operator<<'的重载不明确
error: ambiguous overload for 'operator<<'
当我试图构建我的项目时,我遇到了这个错误:
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;
}
我的猜测是问题出在度符号上,它不是ascii字符。
尝试:
wcout << getDegrees() << L"u00B0";
相关文章:
- C++重载<<具有typedef'd std::vector
- 重载运算符<<:此运算符函数的参数太多
- 在VS 2012上编译,但不使用Netbeans/MinGW-重载<<
- 重载运算符<<用于模板类.即使使用好友关键字也无法获得私人会员
- C++分离成员流重载<<
- 我已经完成了<<运算符重载,但它'It’不起作用
- 重载运算符<<输出地址而不是数据成员
- 重载运算符<<用于ostream语法
- 重载operator< & lt;作为会员打印
- Operator< & lt;重载隐藏其他
- 重载& lt; & lt;为什么我得到以下错误
- 重载ostream&时转换错误无效;operator< & lt;
- operator< & lt;在c++中为类中的类重载
- 重载& lt; & lt;用于打印自定义异常的操作符
- 重载<<运算符错误C2804:二进制'运算符<<'参数太多
- 上Ostream & lt; & lt;重载的困惑
- 重载& lt; & lt;为了我的班级
- 使用带有重载<<endl上的运算符
- 重载& lt; & lt;使用命名空间std
- operator< & lt;重载、名称空间和模板