簡體   English   中英

如何修復“Programmin原理和練習使用C ++”一書中的FLTK頭文件?

[英]How to fix the FLTK header files from 'Programmin principles and practice Using C++' book?

我遵循“使用C ++編程原則和實踐”並進入第12章,其中介紹了GUI。 但是我無法從書中獲取自定義頭文件。 在嘗試了幾本專門為本書安裝fltk的指南之后,我對本指南進行了最深入的研究: https ://bumpyroadtocode.com/2017/08/05/how-to-install-and-use-fltk-1-3-4 -in-視覺工作室2017年完成引導/#評論

我對頭文件進行了相同的更改,因為它們消除了大部分錯誤,但不是全部錯誤。 在Simple_window.h和Simple_window.cpp中注釋掉一些重復聲明后,我只剩下7個錯誤。 但由於我是C ++的新手(否則我可能不會讀這本書)我無法擺脫最后幾個錯誤:(

這些是錯誤:

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:

#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:


//
// 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();
}

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

有兩種方法可以解決這個問題,雖然不知道,這通常更好:

1)在“std_lib_facilities.h”第218-228行中注釋掉隨機數生成器

要么

2)項目 - Properities - 鏈接器 - 所有選項 - 附加選項=>編輯和添加/ FORCE:MULTIPLE

兩者都適合我,也希望你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM