0

This is my first post so I'll try to make it brief

I am currently on chapter 12 of Stroustrup's PPP book, I installed FLTK as they did on this youtube video https://www.youtube.com/watch?v=0eSOPWQ1n6U

Downloaded the header files from Stroustrup's website already and I am trying to make the first example exercise with the GUI where you make a red triangle

code:

#include "Simple_window.h" // get access to our window library
#include "Graph.h" // get access to our graphics library facilities

int main()  
{    
using namespace Graph_lib; // our graphics facilities are in Graph_lib

Point tl(100,100); // to become top left corner of window    
Simple_window win(tl,600,400,"Canvas"); // make a simple window

Polygon poly; // make a shape (a polygon)

poly.add(Point(300,200)); // add a point    
poly.add(Point(350,100)); // add another point    
poly.add(Point(400,200)); // add a third point    
poly.set_color(Color::red); // adjust properties of poly

win.attach (poly); // connect poly to the window

win.wait_for_button(); // give control to the display engine    
}

I have been trying for days different things but I keep getting hit to a wall, this is the error I am getting from the code now after installing everything I know of

1>------ Build started: Project: hello world5, Configuration: Debug Win32 ------
1>  main.cpp
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\gui.h(107): warning C4018: '<': signed/unsigned mismatch
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\gui.h(112): warning C4018: '<': signed/unsigned mismatch
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\gui.h(117): warning C4018: '<': signed/unsigned mismatch
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\simple_window.h(13): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'
1>  c:\users\kenzo\onedrive\documentos\visual studio 2015\simple_window.h(13): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\simple_window.h(13): error C2661: 'Graph_lib::Button::Button': no overloaded function takes 4 arguments
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(9): error C2440: 'initializing': cannot convert from 'initializer list' to 'Graph_lib::Point'
1>  c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(9): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(12): error C2872: 'Polygon': ambiguous symbol
1>  c:\program files (x86)\windows kits\8.1\include\um\wingdi.h(4997): note: could be 'BOOL Polygon(HDC,const POINT *,int)'
1>  c:\users\kenzo\onedrive\documentos\visual studio 2015\graph.h(230): note: or       'Graph_lib::Polygon'
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(12): error C2146: syntax error: missing ';' before identifier 'poly'
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(12): warning C4551: function call missing argument list
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(12): error C2065: 'poly': undeclared identifier
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(14): error C2065: 'poly': undeclared identifier
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(14): error C2228: left of '.add' must have class/struct/union
1>  c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(14): note: type is 'unknown-type'
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(14): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'
1>  c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(14): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(15): error C2065: 'poly': undeclared identifier
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(15): error C2228: left of '.add' must have class/struct/union
1>  c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(15): note: type is 'unknown-type'
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(15): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'
1>  c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(15): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(16): error C2065: 'poly': undeclared identifier
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(16): error C2228: left of '.add' must have class/struct/union
1>  c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(16): note: type is 'unknown-type'
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(16): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'
1>  c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(16): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(17): error C2065: 'poly': undeclared identifier
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(17): error C2228: left of '.set_color' must have class/struct/union
1>  c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(17): note: type is 'unknown-type'
1>c:\users\kenzo\onedrive\documentos\visual studio 2015\projects\hello world5\hello world5\main.cpp(19): error C2065: 'poly': undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Please what shall I do? To be honest i was really looking forward to be messing around with graphic stuff after the first half of the book being so intense and serious

kind regards,

Kenzo

Striezel
  • 3,693
  • 7
  • 23
  • 37
Kenzo
  • 1
  • 5
  • 1
    What is on line 13 of `simple_window.h`? Maybe you should add that file to your question since it is causing the error. – drescherjm Aug 25 '16 at 20:16
  • If it's this one: http://stroustrup.com/Programming/PPP2code/Simple_window.h there is nothing which could explain this. It shall be caused by GUI.h – Christophe Aug 25 '16 at 21:57

4 Answers4

0

The line 13 of simple_windows.h as available here doesn't look bogus. So the error must come from one of the headers included therein.

First candidate (hypothese)

simple_windows.h includes a header GUI.h. I can see on the repository here B.Stroustrup provides two files: Gui.h and GUI.h. On a linux system, these are two different files as filenames are case sensitive. But you're obviously working with windows (Visual Studio 15), that manages filenames insensitive. So the operating system makes no difference (and you certainly have only one of these two files).

As you're working on chapter 12, I suggest to have a try with GUI.h. The first line is:

// This is a GUI support code to the chapters 12-16 of the book

Second candidate (more probable)

I've looked further at the various includes and found an even more probable cause. So if this doesn't solve the issue, then have a look at Point.h. The struct Point therein is defined with default constructor only. The constructor that constructs a point out of its x and y coordinate is commented out:

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

This means that in the statement on line 13 that the compiler highlights as error:

 next_button(Point(x_max()-70,0), 70, 20, "Next", cb_next) { attach(next_button); }

the expression Point(x_max()-70,0) would indeed not be correct and lead to the error that you've reported. Uncomment this constructor

Advice: I haven't read the book. But may be re-read carefully the chapters 1 to 11 to look if there were no step by step instruction/exercises that should have lead you to uncomment this and other lines in the provided source.

Edit: advice 2 - Yes, follow advice 1, because apparently it could be the case as explained here and here and in a couple of other places

Christophe
  • 68,716
  • 7
  • 72
  • 138
0

Firstly, thanks to all for the replies and comments, was glad to hear someone helping me out a bit, very kind of you

So I basically tried everything and I am afraid nothing worked, I started by switching

simple_windows.h

for the version on @Christophe 's link

Then I tried to go with GUI.h, afterwards with lower caps Gui.h instead, leaving the original uppercase GUI on.

When I went onto point.h and saw all that stuff quoted out as you said, I though I finally had it at last! buuuut... didn't work either :'(

I have the feeling like the error message I get on debugging now is kinda shorter tho?

I am starting to feel like maybe I place headers wrong? I try to put them on the include folder from microsoft visual studio/VC, also copy them and place them on the headers file with the compiler open, and sometimes also place them directly on the project folder

at this point I am sorry to be a drag but I would appreciate any other possible solutions

screenshot of something curious with overloads

I have the feeling the +2 overloads are the problem

1>------ Build started: Project: hello world2, Configuration: Debug Win32 ------
1>  main.cpp
1>c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(11): error C2872: 'Polygon': ambiguous symbol
1>  c:\program files (x86)\windows kits\8.1\include\um\wingdi.h(4997): note: could be 'BOOL Polygon(HDC,const POINT *,int)'
1>  c:\program files (x86)\microsoft visual studio 14.0\vc\include\graph.h(230): note: or       'Graph_lib::Polygon'
1>c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(11): error C2146: syntax error: missing ';' before identifier 'poly'
1>c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(11): warning C4551: function call missing argument list
1>c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(11): error C2065: 'poly': undeclared identifier
1>c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(13): error C2065: 'poly': undeclared identifier
1>c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(13): error C2228: left of '.add' must have class/struct/union
1>  c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(13): note: type is 'unknown-type'
1>c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(14): error C2065: 'poly': undeclared identifier
1>c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(14): error C2228: left of '.add' must have class/struct/union
1>  c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(14): note: type is 'unknown-type'
1>c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(15): error C2065: 'poly': undeclared identifier
1>c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(15): error C2228: left of '.add' must have class/struct/union
1>  c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(15): note: type is 'unknown-type'
1>c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(16): error C2065: 'poly': undeclared identifier
1>c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(16): error C2228: left of '.set_color' must have class/struct/union
1>  c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(16): note: type is 'unknown-type'
1>c:\users\kenzo\desktop\hello world2\hello world2\main.cpp(18): error C2065: 'poly': undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Kenzo
  • 1
  • 5
  • Sorry but about gui upper case and lower case: have you looked at their content ? One of the two versions include point.h the other not. Also the modified error message seem to show that the problem shifted away from points to polygon (ambiguous) which causes poly not to be defined and then the cascade of errors. There are several questions on SO about this ambiguity error: just google on the simple_window gui ambiguity and you should find it. Unfortunately i'm away with only my phone so i can't send the link – Christophe Aug 27 '16 at 22:17
  • i found two definitions of poly, one in Graph.h and another one in a header called wingdi.h, ill post screenshots – Kenzo Aug 27 '16 at 22:21
  • 1
    back home. You can have a look at http://www.cplusplus.com/forum/general/121362/ and at https://stackoverflow.com/questions/20973419/trouble-with-polygon-in-stroustrups-ppp-book : both seem to be duplicates of your new error condition (i.e. no longer initialization issues with Point, but now ambiguity with polygons) – Christophe Aug 28 '16 at 21:25
0

I had no idea i had this header somewhere, must have been instaled from the fltk.org zip?

this is from the header downloaded from Stroustrup

i went and sent wingdi.h to the recycle bin and then i got a fatal error at debugging

so the poly must be badly defined at the graph header maybe? I can see some definitions of inside functions within polygon but not a definition of polygon itself, maybe im just a noob

i also went on and changed polygon to Graph_library::Polygon but didn't work

Kenzo
  • 1
  • 5
0

Solution:

You need to uncomment (remove // from those lines) the following lines from the "Point.h" file that you must have downloaded from http://www.stroustrup.com/Programming/PPP2code/

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; }