Stroupstrup图形库错误

use*_*853 2 c++ graphics fltk

我是C++的新手,在我的编程设计和概念类简介中,我们现在使用的是图形.我已经能够使与公正程序FLTK的库,但我们不得不使用了Bjarne的图书馆,如GUI.h,Graph.h,Simple_window.h,Point.h.像简单窗口程序这样的简单程序将无法编译并提供通常的响应:

Simple_window.h:17: error: reference to ‘Window’ is ambiguous
Run Code Online (Sandbox Code Playgroud)

我也尝试使用以下编译:

fltk-config --compile main.cpp
Run Code Online (Sandbox Code Playgroud)

这产生相同的结果.

我已经尝试运行Bjarne在文件夹中提供的make文件,但总是会出现错误并且没有.o文件.

注意:我也尝试在mac OSXUbuntu上进行编译.

v15*_*4c1 6

我从来没有使用过这些库中的任何一个,但是我看到FLTK的教程总是以using namespace fltk;statement 开头,它会导入所有FLTK类,包括fltk::Windowroot根目录.

B. Stroustrup的库包含在名为的名称空间中Graph_lib,它还有一个名为的类Window.现在,文件在开头Simple_window.husing namespace Graph_lib;语句,它导入Graph_lib::Window到根命名空间.这就是模糊性的来源.

所以我建议省略using语句(至少从中using namespace fltk)并使用具有完整规范的FLTK类(例如,fltk::Window而不是仅仅Window).这应该解决模糊性.

作为旁注,这是一个很好的例子,为什么using namespace在头文件中的文件级别是一个坏主意.

参考文献:
http ://www.fltk.org/doc-2.0/html/index.html http://www.stroustrup.com/Programming/Graphics/Simple_window.h

编辑:我试图编译包含Simple_window我自己的库,至少在linux下,它的模糊性似乎是Graph_lib::Window来自库的类和Window来自xlib的typedef 之间的歧义.xlib是C库,你无法真正做任何事情,所以你必须摆脱using namespace Graph_libStroustup的库.

在文件中Simple_window.h:

  • 删除 using namespace Graph_lib;
  • 改变WindowGraph_lib::Window
  • ButtonGraph_lib::Button
  • AddressGraph_lib::Address

然后在文件中Simple_window.cpp:

  • 改变AddressGraph_lib::Address再次
  • reference_to<Simple_window>Graph_lib::reference_to<Simple_window>

然后它应该编译.如果您的版本与stroustrup.com上的版本不同,则可能需要完全限定(添加Graph_lib::)更多类.