Stroupstrup图形库错误 [英] Stroupstrup Graphics Library Errors

查看:187
本文介绍了Stroupstrup图形库错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚接触 C ++ ,在我的介绍编程设计和概念类中,我们现在使用的是图形。我已经能够使用 FLTK 的库来编写程序,但是我们必须使用Bjarne的库,例如 GUI.h Graph.h Simple_window.h Point.h 。一个像简单窗口程序这样的简单程序不会编译并给出通常的响应:

I'm new to C++ and in my Intro to programming design and concepts class we're now on graphics. I've been able to make programs with just FLTK's library but we have to use Bjarne's library such as GUI.h, Graph.h, Simple_window.h, Point.h. A simple program like a simple window program won't compile and gives a usual response of:

Simple_window.h:17: error: reference to ‘Window’ is ambiguous

我也试过编译:

fltk-config --compile main.cpp


b $ b

这产生了相同的结果。

This yields the same results.

我试过运行Bjarne在文件夹中提供的make文件,但总是出现错误,没有 .o 文件。

I have tried running the make file that Bjarne has provided with in the folder but that always comes up with errors and makes no .o files.

注意:我也试过在mac OSX Ubuntu

Note: I have also tried compiling on mac OSX and Ubuntu.

推荐答案

我从来没有使用过这些库, FLTK总是以开头,使用命名空间fltk; 语句,它将所有FLTK类(包括 fltk :: Window

I never used either of those libraries, but I saw that tutorials for FLTK always begin with using namespace fltk; statement, which imports all FLTK classes, including fltk::Window to the root namespace.

B. Stroustrup的库包含在名为 Graph_lib 的命名空间中,并且还有一个名为 Window
现在,文件 Simple_window.h 在开头使用命名空间Graph_lib; 语句, code> Graph_lib :: Window 到根命名空间。

The library by B. Stroustrup is contained in namespace called Graph_lib and it also has a class called Window. Now, the file Simple_window.h has using namespace Graph_lib; statement at the beginning, which imports Graph_lib::Window to the root namespace. And this is where the ambiguity is coming from.

所以我建议省略使用语句从使用命名空间fltk )并使用具有完全规范的FLTK类(例如 fltk :: Window c $ c> Window )。

So I would suggest to omit the using statement (at least from using namespace fltk) and to use FLTK classes with full specification (e.g. fltk::Window instead of just Window). This should solve the ambiguity.

注意,这是一个很好的例子,为什么在文件中使用命名空间

As a side note, this is nice example, why having using namespace at file level in a header file is a bad idea.

参考文献:

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

EDIT :我试图编译包含 Simple_window 的库,至少在linux下,位于库中的 Graph_lib :: Window 和xlib中的typedef Window 之间。 xlib是C库,你不能真正做任何事情,所以你必须摆脱使用命名空间Graph_lib 在Stroustup的库。

EDIT: I tried to compile the library containing Simple_window myself and, at least under linux, it the ambiguity seems to be between class Graph_lib::Window from the library and typedef Window from xlib as well. xlib is C library and you can't really do anything about it, so you will have to get rid of using namespace Graph_lib in Stroustup's library.

在文件 Simple_window.h 中:


  • 删除使用命名空间Graph_lib;

  • 更改窗口 Graph_lib :: Window 到 Graph_lib :: Button code>

  • 地址 Graph_lib :: Address

  • delete using namespace Graph_lib;
  • change Window to Graph_lib::Window
  • Button to Graph_lib::Button
  • and Address to Graph_lib::Address

然后在文件 Simple_window.cpp


  • 更改地址 Graph_lib :: Address / li>
  • reference_to< Simple_window> Graph_lib :: reference_to< Simple_window> / li>
  • change Address to Graph_lib::Address again
  • and reference_to<Simple_window> to Graph_lib::reference_to<Simple_window>

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

Then it should compile. If you have different version than the one that's on stroustrup.com, you may need to fully qualify (add Graph_lib::) more classes.

这篇关于Stroupstrup图形库错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆