Simple_window/Graph.h doesn't work.

Hi guys, I'm trying to learn the grafic interface of c++. I've already installed the fltk libraries in MS. Visual Studio 2013. I should have done it well since the test code of Stroustrup PPP
1
2
3
4
5
6
7
8
9
10
11
#incude <FL/Fl.h>
#incude <FL/Fl_Box.h>
#incude <FL/Fl_Window.h>

int main()
{
FL_Window window(.....); //... stands for the opportune information.
FL_Box box(.....); 
window.show();
return Fl::run();
} 


The problems rises whit the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "Simple_window.h"
#include "Graph.h"

int main()
{
	using namespace Graph_lib;
	Point tl{ 100, 100 };
	Simple_window win{ tl, 600, 400, "Canvas" };
	Graph_lib::Polygon poly;
	poly.add(Point{ 300, 200 }); 
	poly.add(Point{ 350, 100 });
	poly.add(Point{ 400, 200 });
	win.attach(poly);
	win.wait_for_button();

}

In the headers I have the folowing errors:

7 IntelliSense: no suitable constructor exists to convert from "int" to "Graph_lib::Point" c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\Simple_window.h 12 22 Win32Project2
8 IntelliSense: expected a ')' c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\Simple_window.h 12 32 Win32Project2
3 error C2661: 'Graph_lib::Point::Point' : no overloaded function takes 2 arguments c:\program files (x86)\microsoft visual studio 12.0\vc\include\simple_window.h 12 1 Win32Project2
4 error C2661: 'Graph_lib::Button::Button' : no overloaded function takes 4 arguments c:\program files (x86)\microsoft visual studio 12.0\vc\include\simple_window.h 12 1 Win32Project2
5 IntelliSense: no instance of constructor "Graph_lib::Color::Color" matches the argument list
argument types are: (Fl_Color) c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\Graph.h 158 15 Win32Project2
6 IntelliSense: protected function "Graph_lib::Shape::Shape(std::initializer_list<Graph_lib::Point> lst)" (declared at line 118 of "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\Graph.h") is not accessible through a "Graph_lib::Shape" pointer or object c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\Graph.h 237 44 Win32Project2
1 error C2797: 'Shape': list initialization inside member initializer list or non-static data member initializer is not implemented c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 237 1 Win32Project2
2 error C2797: 'Graph_lib::Text::lab': list initialization inside member initializer list or non-static data member initializer is not implemented c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 244 1 Win32Project2


I've already tryed to add the codes Graph/GUI/Simple_window/Window.cpp but the errors skyrocking.
The file are located in http://stroustrup.com/Programming/PPP2code/.
Is there someone who has an idea of what is wrong?
Thank to every one for the attention.
try this :
replace { with (
and } with )

Don't do this to main function braces
It looks like your Simple_window.h is not copied correctly: error messages implies unbalanced brackets, when everything is fine in file in your link.

Two last problems are because VS does not support uniform initialization properly until VS2013.
Hi guys and thank you for the advices.
I've tryed the following change on the header file:
In Graph.h line 237 changed to:
Lines(initializer_list<Point> lst) : Shape(lst) { if (lst.size() % 2) error("odd number of points for Lines"); }
also the 244 has been changed :
Text(Point x, const string& s) : lab(s) { add(x); }
Mooreover I disabled the intellisense's errors and the last lines of comment in point.h.
Now the very easy code
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
#include "std_lib_facilities.h"
#include "Graph.h"
#include "Simple_window.h"

{
   Fl_Window window(600, 400, "My window");

   window.show();
   return Fl::run();
}

Works, but when i try the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    #include <FL/Fl.H>
    #include <FL/Fl_Box.H>
    #include <FL/Fl_Window.H>
    #include "std_lib_facilities.h"
    #include "Graph.h"
    #include "Simple_window.h"
    //#include "point2.h"
    #include "Point.h"
    //#include "GUI.h"

    // Use standard main to have console background:
    int main(int argc, char ** argv)
    {
       Fl_Window *window;
       Fl_Box *box;

       window = new Fl_Window(300, 180);
       box = new Fl_Box(20, 40, 260, 100, "Hello World!");
       Graph_lib::Point tl{ 200, 200 };
       Graph_lib::Simple_window win{ tl, 600, 400, "Canvas" };
       Graph_lib::Polygon poly;
       poly.add(Point{ 300, 200 });
       poly.add(Point{ 350, 100 });
       poly.add(Point{ 400, 200 });
       win.attach(poly);
       box->box(FL_UP_BOX);
       box->labelsize(36);
       box->labelfont(FL_BOLD + FL_ITALIC);
       box->labeltype(FL_SHADOW_LABEL);
       window->end();
       window->show(argc, argv);

       return(Fl::run());


I found the error:
1 error C2039: ‘Simple_window’ : is not a member of ‘Graph_lib’ c:\users\angmarwizardking\documents\visual studio 2013\projects\win32project3\win32project3\source.cpp 21 1 Win32Project3

I'have also tryed to remove the Graph_lib from Simple_window, but this give to me much more errors. any advice?
Thank you anyway for the previous collaboration.
Simple_window is not a member of Graph_lib, so you do not need Graph_lib:: before it.
Yes but as I said, if I try to write the same code with:
1
2
3
 Graph_lib::Point tl{ 200, 200 };
       Simple_window win{ tl, 600, 400, "Canvas" };
       Graph_lib::Polygon poly;

I get the following errors:
12 error LNK1120: 11 unresolved externals C:\Users\Angmarwizardking\Documents\Visual Studio 2013\Projects\Win32Project3\Debug\Win32Project3.exe Win32Project3
1 error LNK2001: unresolved external symbol “protected: virtual void __thiscall Graph_lib::Shape::draw_lines(void)const ” (?draw_lines@Shape@Graph_lib@@MBEXXZ) C:\Users\Angmarwizardking\Documents\Visual Studio 2013\Projects\Win32Project3\Win32Project3\Source.obj Win32Project3
2 error LNK2001: unresolved external symbol “public: virtual void __thiscall Graph_lib::Shape::move(int,int)” (?move@Shape@Graph_lib@@UAEXHH@Z) C:\Users\Angmarwizardking\Documents\Visual Studio 2013\Projects\Win32Project3\Win32Project3\Source.obj Win32Project3
3 error LNK2001: unresolved external symbol “public: virtual void __thiscall Graph_lib::Open_polyline::draw_lines(void)const ” (?draw_lines@Open_polyline@Graph_lib@@UBEXXZ) C:\Users\Angmarwizardking\Documents\Visual Studio 2013\Projects\Win32Project3\Win32Project3\Source.obj Win32Project3
4 error LNK2001: unresolved external symbol “public: virtual void __thiscall Graph_lib::Closed_polyline::draw_lines(void)const ” (?draw_lines@Closed_polyline@Graph_lib@@UBEXXZ) C:\Users\Angmarwizardking\Documents\Visual Studio 2013\Projects\Win32Project3\Win32Project3\Source.obj Win32Project3
5 error LNK2019: unresolved external symbol “public: void __thiscall Graph_lib::Polygon::add(struct Graph_lib::Point)” (?add@Polygon@Graph_lib@@QAEXUPoint@2@@Z) referenced in function _main C:\Users\Angmarwizardking\Documents\Visual Studio 2013\Projects\Win32Project3\Win32Project3\Source.obj Win32Project3
6 error LNK2001: unresolved external symbol “public: virtual void __thiscall Graph_lib::Polygon::draw_lines(void)const ” (?draw_lines@Polygon@Graph_lib@@UBEXXZ) C:\Users\Angmarwizardking\Documents\Visual Studio 2013\Projects\Win32Project3\Win32Project3\Source.obj Win32Project3
7 error LNK2019: unresolved external symbol “public: __thiscall Graph_lib::Window::Window(struct Graph_lib::Point,int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)” (??0Window@Graph_lib@@QAE@UPoint@1@HHABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function “public: __thiscall Simple_window::Simple_window(struct Graph_lib::Point,int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)” (??0Simple_window@@QAE@UPoint@Graph_lib@@HHABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) C:\Users\Angmarwizardking\Documents\Visual Studio 2013\Projects\Win32Project3\Win32Project3\Source.obj Win32Project3
8 error LNK2019: unresolved external symbol “public: void __thiscall Graph_lib::Window::attach(class Graph_lib::Shape &)” (?attach@Window@Graph_lib@@QAEXAAVShape@2@@Z) referenced in function _main C:\Users\Angmarwizardking\Documents\Visual Studio 2013\Projects\Win32Project3\Win32Project3\Source.obj Win32Project3
9 error LNK2019: unresolved external symbol “public: void __thiscall Graph_lib::Window::attach(class Graph_lib::Widget &)” (?attach@Window@Graph_lib@@QAEXAAVWidget@2@@Z) referenced in function “public: __thiscall Simple_window::Simple_window(struct Graph_lib::Point,int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)” (??0Simple_window@@QAE@UPoint@Graph_lib@@HHABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) C:\Users\Angmarwizardking\Documents\Visual Studio 2013\Projects\Win32Project3\Win32Project3\Source.obj Win32Project3
10 error LNK2001: unresolved external symbol “protected: virtual void __thiscall Graph_lib::Window::draw(void)” (?draw@Window@Graph_lib@@MAEXXZ) C:\Users\Angmarwizardking\Documents\Visual Studio 2013\Projects\Win32Project3\Win32Project3\Source.obj Win32Project3
11 error LNK2001: unresolved external symbol “public: virtual void __thiscall Graph_lib::Button::attach(class Graph_lib::Window &)” (?attach@Button@Graph_lib@@UAEXAAVWindow@2@@Z) C:\Users\Angmarwizardking\Documents\Visual Studio 2013\Projects\Win32Project3\Win32Project3\Source.obj Win32Project3
So i don't really know what i have to change....
Thank you again anyway.

Last edited on
Do you compile corresponding cpp files alongside your other files?
If I add the files Simple_window.cpp and Graph.cpp I have more than 100 errors...
I've also tryed to add GUI.cpp and Window.cpp it rises only the number of errors...
If you know another Ide, where this probelms doesn't exist I'll glad abandon VS....
Last edited on
If I add the file Simple_window.cpp and Graph.cpp I have more than 100 errors
How you add it?
On the right of the screen I have 'solution-name project-' in this place there is an icon of a folder named Source Files, right click add->New item->C++ file->add the file copied form the stroustrup web page.
Ok, are they set to be compiled alongside other files? If so, which errors do you have?
for what i know, no.
In the page 437 of ppp2, Stroustup says -about an exercise regarding simple_window-

.... #include "Graph.h" and #include "Simple_window.h" in your code and Graph.cpp and Window.cpp in your project.

When i try to compil the ful project i get some errors like:
1 error C2143: syntax error : missing ';' before '<' c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 88 1 Win32Project3
2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 88 1 Win32Project3
3 error C2238: unexpected token(s) preceding ';' c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 88 1 Win32Project3
4 error C2143: syntax error : missing ';' before '<' c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 89 1 Win32Project3
5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 89 1 Win32Project3
6 error C2238: unexpected token(s) preceding ';' c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 89 1 Win32Project3
7 error C2061: syntax error : identifier 'initializer_list' c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 118 1 Win32Project3
8 error C2535: 'Graph_lib::Shape::Shape(void)' : member function already defined or declared c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 118 1 Win32Project3
9 error C2143: syntax error : missing ';' before '<' c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 157 1 Win32Project3
10 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 157 1 Win32Project3
24 error C3861: 'error': identifier not found c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 237 1 Win32Project3
25 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 245 1 Win32Project3
26 error C2143: syntax error : missing ',' before '&' c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 245 1 Win32Project3
27 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 250 1 Win32Project3
28 error C2143: syntax error : missing ',' before '&' c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 250 1 Win32Project3
29 error C2146: syntax error : missing ';' before identifier 'label' c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 251 1 Win32Project3
30 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 251 1 Win32Project3
32 error C2146: syntax error : missing ';' before identifier 'lab' c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 259 1 Win32Project3
33 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 259 1 Win32Project3
34 error C2065: 's' : undeclared identifier c:\program files (x86)\microsoft visual studio 12.0\vc\include\graph.h 245 1 Win32Project3
35 error C2614: 'Graph_lib::Text' : illegal member initialization: 'lab' is not a base or t3\win32project3\graph.cpp 76 1 Win32Project3
I believe VS2012 does not support initializer lists too.
I suggest update to Visual Studio 2015
I'll follow your advice. Thank you for the kind assistance and patience.
Hi, I have an update of the trouble. Now I have VS 2015 on my pc, when I try to compile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
#include "Simple_window.h"    // if we want that "Next" button
#include "Graph.h" 
#include "std_lib_facilities.h"

using namespace Graph_lib;

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

int main()
try
{
	Point tl(100, 100);     // top-left corner of our window

	Simple_window win(tl, 600, 400, "Canvas");
	// screen coordinate tl for top-left corner
	// window size(600*400)
	// title: Canvas
	win.wait_for_button(); // Display!
}
catch (exception& e) {
	// some error reporting
	return 1;
}
catch (...) {
	// some more error reporting
	return 2;
}


I obtain many warning/note messages -that should not affect the correctness of the code-
And just one error message:
1>c:\users\angmarwizardking\documents\visual studio 2015\projects\win32project1\win32project1\graph.cpp(314): error C2440: 'return': cannot convert from 'std::ifstream' to 'bool'

in graph.ccp, here the code:

http://stroustrup.com/Programming/PPP2code/Graph.cpp

I've already tryed to change
return ff;
with
return !ff.fail();
But it does not work.
Does someone -in particular MiiNiPa ;-)- has any idea of what i can try??
Thank you again!
change it to return (bool)ff;
I've tryed it, but it doesn't work, I get errors message like:


1>Graph.obj : error LNK2019: unresolved external symbol __imp___invalid_parameter referenced in function "char * __cdecl std::_Allocate<char>(unsigned int,char *,bool)" (??$_Allocate@D@std@@YAPADIPAD_N@Z)
1>Source.obj : error LNK2001: unresolved external symbol __imp___invalid_parameter
1>Window.obj : error LNK2001: unresolved external symbol __imp___invalid_parameter
1>Graph.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "char * __cdecl std::_Allocate<char>(unsigned int,char *,bool)" (??$_Allocate@D@std@@YAPADIPAD_N@Z)
1>Source.obj : error LNK2001: unresolved external symbol __imp___CrtDbgReportW
1>Window.obj : error LNK2001: unresolved external symbol __imp___CrtDbgReportW
1>Graph.obj : error LNK2019: unresolved external symbol "public: __thiscall Fl_JPEG_Image::Fl_JPEG_Image(char const *)" (??0Fl_JPEG_Image@@QAE@PBD@Z) referenced in function "public: __thiscall Graph_lib::Image::Image(struct Graph_lib::Point,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,enum Graph_lib::Suffix::Encoding)" (??0Image@Graph_lib@@QAE@UPoint@1@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@W4Encoding@Suffix@1@@Z)


I'll try to delete the function -and related part of code- since it seems not foundamental.
If you have another -easy&fast- solution I'll try, but don't waste your time anymore on this.
Thank you very much for the help, it has been very appreciated!!!



This is really strange actualy. Did you try to make a clean build (VS might not delete object files if cpp file did not change and object files generated by older version of VS might be incompatible with new)
I've tryed with Build->Clean solution and then Rebuild solution. But I get the same kind of errors.....
If you know another reference where i can learn how to use the ftlk facilities -or other equivalent facilities- which doesn't uses the stroustrup code, for me is't same.
Thank you again.
Just wondering how you went with this. I was having the same troubles. After a bit of searching and doing bits and pieces of whats here, my code is compiling but not linking. I'm getting 1 link error which is

error LNK2001: unresolved external symbol "public: virtual void __thiscall Graph_lib::Button::attach(class Graph_lib::Window &)" (?attach@Button@Graph_lib@@UAEXAAVWindow@2@@Z) Chapter12Drills Source.obj

Source.cpp is this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "../../Graph.h"
#include "../../Simple_window.h"

int main() {
	try {
		Point tl{ 100, 100 }; // top left corner of our window
		Simple_window win(tl, 600, 400, "My Window");

		win.wait_for_button(); // display!
	}
	catch (exception& e) {
		//handle errors
	}
	catch (...) {
		//more error handling
	}
}

I'm getting the same link error with Visual Studio 2015 and Visual Studio Express 2013. I'm completely lost as to why this link error is coming up. Any help would be great!
Topic archived. No new replies allowed.