2011-08-19 46 views
0

我正在通過Stroustrup的「Programming Principles ...」的方式工作。我試圖獲得一個簡單的窗口程序編譯,並沒有在Linux或Windows上運氣。Stroustrup的Graph.h

最終,在多次出現問題後,我試圖將Graph.h包含在他的網站中,而不是其他的。我的錯誤是如下(我不知道,因爲我認爲他的代碼是正確的現在給做)

$ g++ window.cpp 
In file included from /usr/include/c++/4.5/ext/hash_map:60:0, 
       from /home/nathan/Documents/c++/std_lib_facilities.h:34, 
       from /usr/include/c++/4.5/Window.h:12, 
       from window.cpp:1: 
/usr/include/c++/4.5/backward/backward_warning.h:28:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. 
In file included from window.cpp:2:0: 
/usr/include/c++/4.5/Graph.h: In constructor ‘Graph_lib::Rectangle::Rectangle(Point, Point)’: 
/usr/include/c++/4.5/Graph.h:203:43: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘<unresolved overloaded function type>’ to binary ‘operator-’ 
/usr/include/c++/4.5/Graph.h:203:55: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘<unresolved overloaded function type>’ to binary ‘operator-’ 
/usr/include/c++/4.5/Graph.h: In constructor ‘Graph_lib::Circle::Circle(Point, int)’: 
/usr/include/c++/4.5/Graph.h:286:26: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator-’ 
/usr/include/c++/4.5/Graph.h:286:32: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator-’ 
/usr/include/c++/4.5/Graph.h: In member function ‘Point Graph_lib::Circle::center() const’: 
/usr/include/c++/4.5/Graph.h:290:49: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘const int’ to binary ‘operator+’ 
/usr/include/c++/4.5/Graph.h:290:63: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘const int’ to binary ‘operator+’ 
/usr/include/c++/4.5/Graph.h: In member function ‘void Graph_lib::Circle::set_radius(int)’: 
/usr/include/c++/4.5/Graph.h:292:57: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator-’ 
/usr/include/c++/4.5/Graph.h:292:71: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator-’`enter code here` 
/usr/include/c++/4.5/Graph.h: In constructor ‘Graph_lib::Ellipse::Ellipse(Point, int, int)’: 
/usr/include/c++/4.5/Graph.h:302:33: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator-’ 
/usr/include/c++/4.5/Graph.h:302:40: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator-’ 
/usr/include/c++/4.5/Graph.h: In member function ‘Point Graph_lib::Ellipse::center() const’: 
/usr/include/c++/4.5/Graph.h:306:49: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘const int’ to binary ‘operator+’ 
/usr/include/c++/4.5/Graph.h:306:62: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘const int’ to binary ‘operator+’ 
/usr/include/c++/4.5/Graph.h: In member function ‘Point Graph_lib::Ellipse::focus1() const’: 
/usr/include/c++/4.5/Graph.h:309:55: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator+’ 
/usr/include/c++/4.5/Graph.h:311:66: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator+’ 
/usr/include/c++/4.5/Graph.h: In member function ‘Point Graph_lib::Ellipse::focus2() const’: 
/usr/include/c++/4.5/Graph.h:316:55: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator-’ 
/usr/include/c++/4.5/Graph.h:318:66: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator-’ 
/usr/include/c++/4.5/Graph.h: In member function ‘void Graph_lib::Ellipse::set_major(int)’: 
/usr/include/c++/4.5/Graph.h:322:56: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator-’ 
/usr/include/c++/4.5/Graph.h:322:70: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator-’ 
/usr/include/c++/4.5/Graph.h: In member function ‘void Graph_lib::Ellipse::set_minor(int)’: 
/usr/include/c++/4.5/Graph.h:324:56: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator-’ 
/usr/include/c++/4.5/Graph.h:324:69: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator-’ 
/usr/include/c++/4.5/Graph.h: In member function ‘void Graph_lib::Image::set_mask(Point, int, int)’: 
/usr/include/c++/4.5/Graph.h:372:65: error: cannot resolve overloaded function ‘x’ based on conversion to type ‘int’ 
/usr/include/c++/4.5/Graph.h:372:74: error: cannot resolve overloaded function ‘y’ based on conversion to type ‘int’ 

不知道這是否是失禮粘貼我的代碼,但無論如何。 我到處尋找,並試圖兩天。我現在感到非常沮喪。請幫忙。

+1

你絕對應該發佈_some_代碼,因爲這個問題目前是無法回答的,但是嘗試將自己限制在一個仍然給出這些錯誤的小片段中,而不是發佈你的代碼。 – hammar

+0

'/ usr/include/C++/4.5 /'似乎是放置這些文件的不好的地方 - 這正是標準庫頭文件所在的地方。 –

回答

0

您是否包含正確的Point.hGraph.h取決於Point.h)?在找到「原理」示例之前,編譯器可能會找到其他一些Point.h文件。

g++ -M Window.cpp 

可能會幫助您確定。


我拉低了整個例如,發現我確實有修復Graph.h兩行得到它來編譯,但他們無關,與你在得到錯誤的行,Point.h,或Point類型。

在140-142 Graph.h行,我不得不改變:

private: // prevent copying 
    Vector_ref(const Vector&); 
    Vector_ref& operator=(const vector&); 

到:

private: // prevent copying 
    Vector_ref(const Vector_ref&); 
    Vector_ref& operator=(const Vector_ref&); 

我假設你已經做到了這一點,因爲編譯器越來越過去那些行不投訴。在此修復之後,Window.cpp編譯正常(但不鏈接,因爲我沒有構建該示例所依賴的庫)。

我用MinGW 4.5.1做了這個。

+0

對不起 - 我最初發布了讓GCC列出包含文件位置的錯誤選項。 '-E -dM'對此沒有幫助;使用'-M'。 –

+0

哇,勇敢。當你聽到雷聲時,已經太晚了。 –

+0

謝謝!這樣快速的回覆!這似乎減輕了一些錯誤,儘管我得到的是他的課程沒有我正在嘗試使用的成員,所以我現在將研究這些錯誤。爲什麼這有問題?他確實測試過它? –

相關問題