A
A
Anton Boyarshinov2016-02-16 22:38:28
C++ / C#
Anton Boyarshinov, 2016-02-16 22:38:28

Stroustrup, chapter 12, how to fix the code?

Came to chapter 12 (Programming, principles and practice of use), the section on displaying. His code has been slightly altered in his own way, for which he has made his own header files. Ok, I downloaded it from the site, included it in the project, installed FLTK, checked FLTK - it works. Actually, on the very first line of code from the book, the work is over.

Ошибка	1	error LNK2001: неразрешенный внешний символ ""protected: virtual void __thiscall Graph_lib::Window::draw(void)" ([email protected]@[email protected]@MAEXXZ)"
  C:\Users\WTF\documents\visual studio 2013\Projects\ConsoleApplication2\testing\testing.obj	testing

Ошибка	2	error LNK2019: ссылка на неразрешенный внешний символ "public: __thiscall Simple_window::Simple_window(struct Point,int,int,class std::basic_string<char,struct std::char_traits<char>,
class std::allocator<char> > const &)" ([email protected]@[email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) в
 функции _main	C:\Users\WTF\documents\visual studio 2013\Projects\ConsoleApplication2\testing\testing.obj	testing

Question - what could be the problem? I thought some kind of announcement was missing - I looked. All the files are in place, the announcements seem to be too.
I don't know how it is more convenient to lay out the code, because there are several files included. Here are the code snippets of the function declarations mentioned in the error:
Simple_window (Simple_window.h) :
using namespace Graph_lib;

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

    bool wait_for_button(); // simple event loop

private:
    Button next_button;     // the "next" button
    bool button_pushed;     // implementation detail

    static void cb_next(Address, Address); // callback for next_button
    void next();            // action to be done when next_button is pressed

};

Simple_window (Simple_window.cpp):
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);
}

Simple_window inherits from Window, its code is from .h and .cpp respectively:
class Window : public Fl_Window { 
    public:
        // let the system pick the location:
        Window(int w, int h, const string& title);
        // top left corner in xy
        Window(Point xy, int w, int h, const string& title);    

        virtual ~Window() { }

        int x_max() const { return w; }
        int y_max() const { return h; }

        void resize(int ww, int hh) { w=ww, h=hh; size(ww,hh); }

        void set_label(const string& s) { copy_label(s.c_str()); }

        void attach(Shape& s) { shapes.push_back(&s); }
        void attach(Widget&);

        void detach(Shape& s);     // remove s from shapes 
        void detach(Widget& w);    // remove w from window (deactivates callbacks)

        void put_on_top(Shape& p); // put p on top of other shapes

    protected:
        void draw();

    private:
        vector<Shape*> shapes;     // shapes attached to window
        int w,h;                   // window size

        void init();
    };

Window::Window(int ww, int hh, const string& title)
:Fl_Window(ww,hh,title.c_str()),w(ww),h(hh)
{
  init();
}

Window::Window(Point xy, int ww, int hh, const string& title)
:Fl_Window(xy.x,xy.y,ww,hh,title.c_str()),w(ww),h(hh)
{ 
  init();
}

void Window::init()
{
   resizable(this);
   show();
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AtomKrieg, 2016-02-17
@AtomKrieg

void draw() method is not declared in window.cpp

A
Anton Boyarshinov, 2016-02-17
@Zhyki

I tried to comment out protected - the same error, but with public . I didn’t find any calls to this method at all, only a Git definition with flat code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question