我正在通过Stroustrup的“编程原则......”来解决这个问题。我正在尝试编译一个简单的窗口程序,并且在linux或windows上没有运气。
最终,在遇到多个问题后,我试图将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’
不知道粘贴我的所有代码是否是一种失礼,但无论如何。 我到处寻找,已经尝试了两天。我现在感到非常沮丧。请帮忙。
答案 0 :(得分:0)
您是否包含了正确的Point.h
(Graph.h
取决于Point.h
)?在找到“Principles”示例中的文件之前,编译器可能正在找到其他Point.h
文件。
g++ -M Window.cpp
可能会帮助您确定。
我删除了整个示例,发现我确实需要修复Graph.h
中的两行来进行编译,但它们与您遇到错误的行无关,{{1 },或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&);
编译正常(但没有链接,因为我没有构建示例所依赖的库)。
我使用MinGW 4.5.1做到了这一点。