问题描述
我目前正在阅读Bjarne Stroustrup的“使用C ++ 2nd Edition的原理和实践”,而我才刚刚开始第12章。但是我似乎无法运行此代码。
#include "Simple_window.h" // get access to our window library
#include "Graph.h" // get access to our graphics library facilities
int main()
{
using namespace Graph_lib; // our graphics facilities are in Graph_lib
Point tl {100,100}; // to become top left corner of window
Simple_window win {tl,600,400,"Canvas"}; // make a simple window
polygon poly; // make a shape (a polygon)
poly.add(Point{300,200}); // add a point
poly.add(Point{350,100}); // add another point
poly.add(Point{400,200}); // add a third point
poly.set_color(Color::red); // adjust properties of poly
win.attach (poly); // connect poly to the window
win.wait_for_button(); // give control to the display engine
}
错误消息:
Severity Code Description Project File Line Suppression State
Error (active) E0135 class "Simple_window" has no member "attach" Project7 c:\Users\HP\source\repos\Project7\Project7\Source.cpp 13
Error (active) E1696 cannot open source file "GUI.h" Project7 c:\Users\HP\source\repos\Project7\Project7\Simple_window.h 2
Error (active) E0725 name must be a namespace name Project7 c:\Users\HP\source\repos\Project7\Project7\Simple_window.h 4
Error (active) E1696 cannot open source file "Graph.h" Project7 c:\Users\HP\source\repos\Project7\Project7\Source.cpp 2
Error (active) E0725 name must be a namespace name Project7 c:\Users\HP\source\repos\Project7\Project7\Source.cpp 5
Error (active) E0020 identifier "Point" is undefined Project7 c:\Users\HP\source\repos\Project7\Project7\Source.cpp 6
Error (active) E0020 identifier "polygon" is undefined Project7 c:\Users\HP\source\repos\Project7\Project7\Source.cpp 8
Error (active) E0020 identifier "Point" is undefined Project7 c:\Users\HP\source\repos\Project7\Project7\Source.cpp 9
Error (active) E0018 expected a ')' Project7 c:\Users\HP\source\repos\Project7\Project7\Source.cpp 9
Error (active) E0018 expected a ')' Project7 c:\Users\HP\source\repos\Project7\Project7\Source.cpp 10
Error (active) E0018 expected a ')' Project7 c:\Users\HP\source\repos\Project7\Project7\Source.cpp 11
Error (active) E0276 name followed by '::' must be a class or namespace name Project7 c:\Users\HP\source\repos\Project7\Project7\Source.cpp 12
Error C1083 Cannot open include file: 'GUI.h': No such file or directory Project7 c:\users\hp\source\repos\project7\project7\simple_window.h 2
我尝试将代码中指定的头文件粘贴到程序中,但是它不起作用。我尝试实现FLTK 1.3.5并将其也链接到VS2019,但它继续显示错误消息。请帮助我解决这个问题。
这里是他书中该章的参考:https://www.stroustrup.com/programming_ch12.pdf
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)