Stroustrup's GUI Interface Library Question

Feb 17, 2013 at 7:45pm
I am reading "Programming Principles and Practice Using C++" by Bjarne Stroustrup. I am currently on chapter 13. The chapter is about GUI programming, the purpose of which is to get you used to reading other people's code and using libraries. Here are the libraries I use:

http://www.stroustrup.com/Programming/Graphics/

http://www.stroustrup.com/Programming/FLTK/


The thing I don't understand is that every class, like Rectangle, Polygon, ect... which is from the base class Shape has a function void draw_lines() const which draws the lines of a shape (it is different for each shape), but void draw_lines() const is not called in any of the constructors of the classes such as Rectangle, Polygon, ect... The only function called in the constructors of those classes is void Shape::add(Point p), it adds a Point to the member variable vector<Point> Shape::points (basically Point is a coordinate system for the window. So when you make an object of class Rectangle you pass all the arguments and it calls void Shape::add(Point p), but it doesn't call void Shape::Rectangle::void draw_lines(). My question is how are the lines drawn if void Shape::Rectangle::void draw_lines() isn't called in the constructor or in void Shape::add(Point p)?
Last edited on Feb 17, 2013 at 7:50pm
Feb 17, 2013 at 9:21pm
draw_lines() is called from Shape::draw(), which is called from Window::draw().
Feb 18, 2013 at 8:11am
@Peter87

Thanks for the fast reply! But I still don't get who calls Window::draw()? I thought it would be called in Window::attach() when you attach a shape to a window, but it's not.
Feb 18, 2013 at 12:17pm
The Window::draw() function is a virtual function and is called from somewhere in the FLTK library.
Feb 18, 2013 at 3:04pm
Thanks again!
Topic archived. No new replies allowed.