首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复“使用C++的编程原理和实践”一书中的FLTK头文件?

如何修复“使用C++的编程原理和实践”一书中的FLTK头文件?
EN

Stack Overflow用户
提问于 2019-05-12 14:14:41
回答 1查看 650关注 0票数 2

我遵循“使用C++编程的原则和实践”,第12章介绍了GUI。但是,我无法使自定义头文件从书中工作。在尝试了几个专门为本书安装fltk的指南之后,我从以下指南中得到了最远的信息:https://bumpyroadtocode.com/2017/08/05/how-to-install-and-use-fltk-1-3-4-in-visual-studio-2017-complete-guide/#comments

我对头文件进行了与它们相同的更改,这消除了大多数错误,但不是全部错误。在注释掉Simple_window.h和Simple_window.cpp中的一些重复声明之后,我只剩下7个错误。但是,由于我是C++新手(否则我可能不会读这本书),我无法消除最后几个错误:

这些都是错误:

代码语言:javascript
复制
Severity    Code    Description Project File    Line    Suppression State
Error   LNK2005 "void __cdecl seed_randint(int)" (?seed_randint@@YAXH@Z) already defined in Graph.obj   Programming Principles and Practice Using C++   C:\Users\CM Storm i7\source\repos\Programming Principles and Practice Using C++\Programming Principles and Practice Using C++\Window.obj    1   
Error   LNK2005 "class std::mersenne_twister_engine<unsigned int,32,624,397,31,2567483615,11,4294967295,7,2636928640,15,4022730752,18,1812433253> & __cdecl get_rand(void)" (?get_rand@@YAAAV?$mersenne_twister_engine@I$0CA@$0CHA@$0BIN@$0BP@$0JJAILANP@$0L@$0PPPPPPPP@$06$0JNCMFGIA@$0P@$0OPMGAAAA@$0BC@$0GMAHIJGF@@std@@XZ) already defined in Graph.obj Programming Principles and Practice Using C++   C:\Users\CM Storm i7\source\repos\Programming Principles and Practice Using C++\Programming Principles and Practice Using C++\GUI.obj   1   
Error   LNK2005 "class std::mersenne_twister_engine<unsigned int,32,624,397,31,2567483615,11,4294967295,7,2636928640,15,4022730752,18,1812433253> & __cdecl get_rand(void)" (?get_rand@@YAAAV?$mersenne_twister_engine@I$0CA@$0CHA@$0BIN@$0BP@$0JJAILANP@$0L@$0PPPPPPPP@$06$0JNCMFGIA@$0P@$0OPMGAAAA@$0BC@$0GMAHIJGF@@std@@XZ) already defined in Graph.obj Programming Principles and Practice Using C++   C:\Users\CM Storm i7\source\repos\Programming Principles and Practice Using C++\Programming Principles and Practice Using C++\Simple_window.obj 1   
Error   LNK2005 "class std::mersenne_twister_engine<unsigned int,32,624,397,31,2567483615,11,4294967295,7,2636928640,15,4022730752,18,1812433253> & __cdecl get_rand(void)" (?get_rand@@YAAAV?$mersenne_twister_engine@I$0CA@$0CHA@$0BIN@$0BP@$0JJAILANP@$0L@$0PPPPPPPP@$06$0JNCMFGIA@$0P@$0OPMGAAAA@$0BC@$0GMAHIJGF@@std@@XZ) already defined in Graph.obj Programming Principles and Practice Using C++   C:\Users\CM Storm i7\source\repos\Programming Principles and Practice Using C++\Programming Principles and Practice Using C++\Window.obj    1   
Error   LNK2005 "void __cdecl seed_randint(int)" (?seed_randint@@YAXH@Z) already defined in Graph.obj   Programming Principles and Practice Using C++   C:\Users\CM Storm i7\source\repos\Programming Principles and Practice Using C++\Programming Principles and Practice Using C++\GUI.obj   1   
Error   LNK2005 "void __cdecl seed_randint(int)" (?seed_randint@@YAXH@Z) already defined in Graph.obj   Programming Principles and Practice Using C++   C:\Users\CM Storm i7\source\repos\Programming Principles and Practice Using C++\Programming Principles and Practice Using C++\Simple_window.obj 1   
Error   LNK1169 one or more multiply defined symbols found  Programming Principles and Practice Using C++   C:\Users\CM Storm i7\source\repos\Programming Principles and Practice Using C++\Debug\Programming Principles and Practice Using C++.exe 1   

这是Simple_window.h:

代码语言:javascript
复制
#include "GUI.h"    // for Simple_window only (doesn't really belong in Window.h)

using namespace Graph_lib;

// Simple_window is basic scaffolding for ultra-simple interaction with graphics
// it provides one window with one "next" button for ultra-simple animation

struct Simple_window : Graph_lib::Window {
    Simple_window(Point xy, int w, int h, const string& title);

    /*
        : Window(xy, w, h, title),
        button_pushed(false),
        next_button(Point(x_max() - 70, 0), 70, 20, "Next", cb_next) {
        attach(next_button);
    }
    */
    bool wait_for_button();
        // modified event loop
        // handle all events (as per default), but quit when button_pushed becomes true
        // this allows graphics without control inversion
    /*
    {
        while (!button_pushed) Fl::wait();
        button_pushed = false;
        Fl::redraw();
    }
    */
    Button next_button;
private:
    bool button_pushed;

    static void cb_next(Address, Address addr); // callback for next_button
    //  { reference_to<Simple_window>(addr).next(); }
    /*
    {
        static_cast<Simple_window*>(addr)->next();
    }
    */
    void next(); //{ button_pushed = true; }

};

最后是Simple_window.cpp:

代码语言:javascript
复制
//
// This is a GUI support code to the chapters 12-16 of the book
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//

#include "Simple_window.h"

//------------------------------------------------------------------------------

Simple_window::Simple_window(Point xy, int w, int h, const string& title) :
    Window(xy, w, h, title),
    next_button(Point(x_max() - 70, 0), 70, 20, "Next", cb_next),
    button_pushed(false)
{
    attach(next_button);
}

//------------------------------------------------------------------------------

bool Simple_window::wait_for_button()
// modified event loop:
// handle all events (as per default), quit when button_pushed becomes true
// this allows graphics without control inversion
{
    show();
    button_pushed = false;
#if 1
    // Simpler handler
    while (!button_pushed) Fl::wait();
    Fl::redraw();
#else
    // To handle the case where the user presses the X button in the window frame
    // to kill the application, change the condition to 0 to enable this branch.
    Fl::run();
#endif
    return button_pushed;
}

//------------------------------------------------------------------------------

void Simple_window::cb_next(Address, Address pw)
// call Simple_window::next() for the window located at pw
{
    reference_to<Simple_window>(pw).next();
}

//------------------------------------------------------------------------------

void Simple_window::next()
{
    button_pushed = true;
    hide();
}

//------------------------------------------------------------------------------
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-28 06:57:51

有两种解决这个问题的办法,虽然不知道,但一般说来更好:

1)注释掉"std_lib_facilities.h“行218-228中的随机数生成器。

2)项目-属性-链接器-所有选项-附加选项=>编辑和添加/FORCE:MULTIPLE

两个人都为我工作,希望你也一样。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56100098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档