2012-07-17 62 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