2012-07-17 73 views
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; 
} 
+1

显示你包括,也头。 – 2012-07-17 12:55:39

+0

你的函数** getDegrees()**返回什么? – TJ1 2012-07-17 12:59:41

+0

我添加了getDegrees和头文件的代码。 – 2012-07-17 13:13:14

回答

2

我的猜测是,问题在于程度的标志,这是不是一个ASCII字符。

尝试,而不是:

wcout << getDegrees() << L"\u00B0"; 
+0

我测试了你的代码,只是简单地用“hello”替换字符串,它仍然给出了相同的错误。 – 2012-07-17 13:47:21

+0

@iSelkiies包括。 – 2012-07-17 13:55:12

+0

或者只是'“\ xB0”'。 (度数符号是我能看到的唯一的东西,但是即使如此,'...'的类型应该总是'char const []',否则编译器应该抱怨它。) – 2012-07-17 13:57:05