Stroupstrup Graphics Library Errors

淺唱寂寞╮ 提交于 2019-12-06 11:22:51

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.

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.

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.

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

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.

In the file Simple_window.h:

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

Then in the file Simple_window.cpp:

  • change Address to Graph_lib::Address again
  • and reference_to<Simple_window> to Graph_lib::reference_to<Simple_window>

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.

I just had the same kind of problems (unresolved external symbols) using Simple_window.h and trying to compile a the following peace of code:

    int main(){

    // create a reference point for the window
    Point topLeft(50,50);
    // initialize a Simple_window object to size: 600x400 pixels, labeled: My window
    Simple_window myWindow(topLeft, 600, 400, "My window");
    // pass control to GUI 
    myWindow.wait_for_button();

    return 0;
    }

The solution was to add to the project (along with the main.cpp) all the respective .cpp files of the included .h files:("Graph.h", "Window.h", "Simple_window.h", "GUI.h")

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!