Implementing FLTK in VS Stroustrup

I'm working my way through Stroustrup's Programming Principles And Practice Using C++, and I have reached chapter 12.
In this chapter, you are required to use the FLTK graphic library.
Since the description in the book is a bit outdated, I had to search around a bit for a usable guide. This is the one I ended up going with:
https://bumpyroadtocode.com/2017/08/29/how-to-install-and-use-fltk-1-3-4-in-visual-studio-2017-complete-guide-2-0-no-cross-contamination/
After a bit of troubleshooting I managed to get to the fourth and final step.
In it, you link up all the headers as well as repeating some of the earlier steps to run this piece of code:

#include "Graph.h"
#include "Simple_window.h"

int main()
{
using namespace Graph_lib;

Point tl(150, 150);
Simple_window win(tl, 600, 400, "My window");
win.wait_for_button();
}

But after a lot of checking and rechecking I still getting around 15 errors:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  Severity	Code	Description	Project	File	Line	Suppression State
Warning	C4018	'<': signed/unsigned mismatch	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\window.cpp	59	
Warning	C4244	'=': conversion from 'double' to 'int', possible loss of data	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\graph.cpp	56	
Warning	C4244	'=': conversion from 'double' to 'int', possible loss of data	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\graph.cpp	57	
Error	C2440	'initializing': cannot convert from 'initializer list' to 'Graph_lib::Point'	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\graph.cpp	74	
Error	C2440	'<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\graph.cpp	148	
Error	C2440	'<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\graph.cpp	169	
Error	C2664	'Graph_lib::Text::Text(const Graph_lib::Text &)': cannot convert argument 1 from 'std::string' to 'const Graph_lib::Text &'	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\graph.cpp	169	
Error	C2440	'<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\graph.cpp	175	
Error	C2440	'<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\graph.cpp	180	
Error	C2660	'Graph_lib::Lines::add': function does not take 1 arguments	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\graph.cpp	180	
Error	C2440	'<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\graph.cpp	190	
Error	C2440	'<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\graph.cpp	195	
Error	C2660	'Graph_lib::Lines::add': function does not take 1 arguments	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\graph.cpp	195	
Error	C2440	'<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\simple_window.h	13	
Error	C2661	'Graph_lib::Button::Button': no overloaded function takes 4 arguments	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\simple_window.h	13	
Error	C2440	'initializing': cannot convert from 'initializer list' to 'Graph_lib::Point'	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\graph_drill.cpp	15	
Error	C2440	'<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\gui.cpp	67	
Error	C2440	'<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\gui.cpp	71	
Warning	C4018	'<': signed/unsigned mismatch	C12 - Graphic Drill	c:\users\simon\source\repos\c12 - graphic drill\c12 - graphic drill\window.cpp	61	

I was hoping someone here could help me solve this problem, as I have no idea how to deal with this at my current level and the guy who made the guide, doesn't seem to respond to comments, currently.

I've linked the sources and headers below.
std_lib_facilities.h: https://pastebin.com/JRHi5Pze
fltk.h: https://pastebin.com/3khmmh3b
Graph.h: https://pastebin.com/DteUSwe5
GUI.h: https://pastebin.com/4Sp8bUfv
Point.h: https://pastebin.com/grdpYX7F
simple_window.h: https://pastebin.com/L7tcWy96
Window.h: https://pastebin.com/3uWeEWeG

graph_drill.cpp: https://pastebin.com/AxQ22Efw
Graph.cpp: https://pastebin.com/MsQHDgEt
Window.cpp: https://pastebin.com/ySUzcZZh

I should mention, that I decided to add the paths to “library directories” and “additional include directories” to the release versions, even though the guide didn't mention it, as otherwise, I would get linking errors about the program being unable to find the source file “FL/Fl_Window.h”.

Regards

Simon


Did you make Point.h?
Try changing the Point struct to look like this and see if it makes a difference.
1
2
3
4
struct Point {
    int x, y;
    Point(int x, int y) : x(x), y(y) {}
};


BTW, not finding a header is still just a compiler error, not a linker error.
Last edited on
Thank you very much, that actually worked, what gave you the clue?

BTW, not finding a header is still just a compiler error, not a linker error.

I guess I already knew that, but I had somehow gotten it into my head, that anything to do with headers, would automatically be a linker error. Good to know.
Most of the errors mentioned Point. Looking at the first two or three locations they all involved initializing a Point struct with two ints, but there wasn't a ctor that takes two ints (or any ctor).

I certainly didn't expect the Graph_lib::Text::Text(const Graph_lib::Text &) errors to go away, though. I couldn't figure that one out.
Most of the errors mentioned Point. Looking at the first two or three locations they all involved initializing a Point struct with two ints, but there wasn't a ctor that takes two ints (or any ctor).


I see. I guess that wasn't necessary(?) when the guide was made, even though it was only around half a year ago, as the last time it was successfully tested, was apparently 30.11.2017. I should make a comment about that, in case it could come in handy for anyone else reading that guide.
Are you sure Point.h is part of fltk? I assumed that you wrote it. I dl'ed the latest fltk and there's no Point.h in it anywhere. Where did you get it?
closed account (E0p9LyTq)
tpb wrote:
Are you sure Point.h is part of fltk?

There are several source files created during the course of reading Stroustrup's Programming book, Point.h is one of them.

support code for PPP2 - http://www.stroustrup.com/Programming/PPP2code
@FurryGuy, Oh, I see. Point.h appears like this in the code you link:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#ifndef POINT_GUARD
#define POINT_GUARD

//typedef void (*Callback)(void*,void*);

namespace Graph_lib {

struct Point {
	int x,y;
//	Point(int xx, int yy) : x(xx), y(yy) { }
//	Point() :x(0), y(0) { }

//	Point& operator+=(Point d) { x+=d.x; y+=d.y; return *this; }
};

inline bool operator==(Point a, Point b) { return a.x==b.x && a.y==b.y; }

inline bool operator!=(Point a, Point b) { return !(a==b); }


}
#endif 

So the ctors are there, but they are commented out. I suspect that the OP was supposed to build that file up piece by piece and forgot to add the ctors.
Topic archived. No new replies allowed.