Header Errors

Write your question here.
How do I correct the following errors?

1>------ Build started: Project: C12Window, Configuration: Debug Win32 ------
1>  C12Window.cpp
1>c:\users\phztfte1\documents\visual studio 2013\projects\c12window\c12window\graph.h(237): error C2797: 'Shape': list initialization inside member initializer list or non-static data member initializer is not implemented
1>c:\users\phztfte1\documents\visual studio 2013\projects\c12window\c12window\graph.h(244): error C2797: 'Graph_lib::Text::lab': list initialization inside member initializer list or non-static data member initializer is not implemented
1>c:\users\phztfte1\documents\visual studio 2013\projects\c12window\c12window\gui.h(106): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\phztfte1\documents\visual studio 2013\projects\c12window\c12window\gui.h(111): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\phztfte1\documents\visual studio 2013\projects\c12window\c12window\gui.h(116): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\phztfte1\documents\visual studio 2013\projects\c12window\c12window\simple_window.h(12): error C2661: 'Graph_lib::Point::Point' : no overloaded function takes 2 arguments
1>c:\users\phztfte1\documents\visual studio 2013\projects\c12window\c12window\simple_window.h(12): error C2661: 'Graph_lib::Button::Button' : no overloaded function takes 4 arguments
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I wrote a simple program to test if the headers were functioning properly.
Here is my main program:
1
2
3
4
5
6
7
#include "Simple_window.h"
#include "Graph.h"

int main()
{
	return 0;
}


Here is the header file Simple_window.h. The boldface line has errors: no suitable constructor exists to convert "int" to "Graph_lib::Point" for x_max() and expected a ')' for the comma after the first 70.
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
34
35
36
37
38
#include "GUI.h"	// for Simple_window only (doesn't really belong in Window.h)

using namespace Graph_lib;

// Simple_window is basic scaffolding for ultra-simple interaction with graphics
// it provides one window with one "next" button for ultra-simple animation

struct Simple_window : Window {
	Simple_window(Point xy, int w, int h, const string& title)
		: Window(xy, w, h, title),
		button_pushed(false),
		next_button(Point(x_max() - 70, 0), 70, 20, "Next", cb_next) {
		attach(next_button);
	}

	void wait_for_button()
		// modified event loop
		// handle all events (as per default), but quit when button_pushed becomes true
		// this allows graphics without control inversion
	{
		while (!button_pushed) Fl::wait();
		button_pushed = false;
		Fl::redraw();
	}

	Button next_button;
private:
	bool button_pushed;

	static void cb_next(Address, Address addr) // callback for next_button
		//	{ reference_to<Simple_window>(addr).next(); }
	{
		static_cast<Simple_window*>(addr)->next();
	}

	void next() { button_pushed = true; }

};



The GUI.h file follows:
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//
// This is a GUI support code to the chapters 12-16 of the book
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//

#ifndef GUI_GUARD
#define GUI_GUARD

#include "Window.h"
#include "Graph.h"

namespace Graph_lib {

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

	typedef void* Address;    // Address is a synonym for void*
	typedef void(*Callback)(Address, Address);    // FLTK's required function type for all callbacks

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

	template<class W> W& reference_to(Address pw)
		// treat an address as a reference to a W
	{
		return *static_cast<W*>(pw);
	}

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

	class Widget {
		// Widget is a handle to an Fl_widget - it is *not* an Fl_widget
		// We try to keep our interface classes at arm's length from FLTK
	public:
		Widget(Point xy, int w, int h, const string& s, Callback cb)
			: loc(xy), width(w), height(h), label(s), do_it(cb)
		{}

		virtual void move(int dx, int dy) { hide(); pw->position(loc.x += dx, loc.y += dy); show(); }
		virtual void hide() { pw->hide(); }
		virtual void show() { pw->show(); }
		virtual void attach(Window&) = 0;

		Point loc;
		int width;
		int height;
		string label;
		Callback do_it;

		virtual ~Widget() { }

	protected:
		Window* own;    // every Widget belongs to a Window
		Fl_Widget* pw;  // connection to the FLTK Widget
	private:
		Widget& operator=(const Widget&); // don't copy Widgets
		Widget(const Widget&);
	};

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

	struct Button : Widget {
		Button(Point xy, int w, int h, const string& label, Callback cb)
			: Widget(xy, w, h, label, cb)
		{}

		void attach(Window&);
	};

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

	struct In_box : Widget {
		In_box(Point xy, int w, int h, const string& s)
			:Widget(xy, w, h, s, 0) { }
		int get_int();
		string get_string();

		void attach(Window& win);
	};

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

	struct Out_box : Widget {
		Out_box(Point xy, int w, int h, const string& s)
			:Widget(xy, w, h, s, 0) { }
		void put(int);
		void put(const string&);

		void attach(Window& win);
	};

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

	struct Menu : Widget {
		enum Kind { horizontal, vertical };
		Menu(Point xy, int w, int h, Kind kk, const string& label)
			: Widget(xy, w, h, label, 0), k(kk), offset(0)
		{}

		Vector_ref<Button> selection;
		Kind k;
		int offset;
		int attach(Button& b);      // Menu does not delete &b
		int attach(Button* p);      // Menu deletes p

		void show()                 // show all buttons
		{
			for (unsigned int i = 0; i<selection.size(); ++i)
				selection[i].show();
		}
		void hide()                 // hide all buttons
		{
			for (unsigned int i = 0; i<selection.size(); ++i)
				selection[i].hide();
		}
		void move(int dx, int dy)   // move all buttons
		{
			for (unsigned int i = 0; i<selection.size(); ++i)
				selection[i].move(dx, dy);
		}

		void attach(Window& win)    // attach all buttons
		{
			for (int i = 0; i<selection.size(); ++i) win.attach(selection[i]);
			own = &win;
		}

	};

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

} // of namespace Graph_lib

#endif // GUI_GUARD 


The Graph.h file is too large to include in this post but can be found at www.stroupstrup.com/Programming in support code for PPP2. I made the following changes in boldface, however:
1
2
3
4
5
6
7
8
9
#ifndef GRAPH_GUARD
#define GRAPH_GUARD 1

#include "Point.h"
//#include<vector> commented out
//#include<string>
//#include<cmath>
#include "fltk.h"
#include "std_lib_facilities.h" // deleted '//' 
Last edited on
graph.h(237): error C2797 ...

The first error is on line 237 of graph.h. Too bad you did not include that bit of code.

The problem seems to relate to initialization syntax. Different versions of C++ standard do touch that subject. Is it possible that the version supported by your compiler expects different syntax than what the code is written in?
Here is part of the code from Graph.h. Lines 237 and 244 have been boldfaced.
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
struct Lines : Shape {	// indepentdent lines
		Lines() {}
		Lines(initializer_list<Point> lst) : Shape{ lst } { if (lst.size() % 2) error("odd number of points for Lines"); }		
                void draw_lines() const;
		void add(Point p1, Point p2) { Shape::add(p1); Shape::add(p2); }
	};

	struct Text : Shape {
		// the point is the bottom left of the first letter
		Text(Point x, const string& s) : lab{ s } { add(x); }
            void draw_lines() const;

		void set_label(const string& s) { lab = s; }
		string label() const { return lab; }

		void set_font(Font f) { fnt = f; }
		Font font() const { return Font(fnt); }

		void set_font_size(int s) { fnt_sz = s; }
		int font_size() const { return fnt_sz; }
	private:
		string lab;	// label
		Font fnt{ fl_font() };
		int fnt_sz{ (14<fl_size()) ? fl_size() : 14 };	// at least 14 point
	};
Last edited on
Braces. Try parentheses:
1
2
3
4
5
6
7
8
9
10
11
12
Lines::Lines( initializer_list<Point> lst )
: Shape( lst )
{
  if ( lst.size() % 2 ) error("odd number of points for Lines");
}


Text::Text( Point x, const string& s )
: lab( s )
{
  add(x);
}

Feeling difficulty in C++ as a beginner?
Simply subscribe to my blog.
http://khgamujtaba.blogspot.com
Thank you, keskiverto. I am down to two errors now. I got rid of the warnings of signed/unsigned mismatch in GUI.h by changing the for statement from
for (unsigned int i = 0; i<selection.size(); ++i) to for (int i = 0; i<selection.size(); ++i)

The last two errors are in the boldfaced statement from Simple_window.h:
1
2
3
4
5
6
7
struct Simple_window : Window {
	Simple_window(Point xy, int w, int h, const string& title)
		: Window(xy, w, h, title),
		button_pushed(false),
		next_button(Point(x_max() - 70, 0), 70, 20, "Next", cb_next) {
		attach(next_button);
	}

The precompiled error messages are no suitable constructor exists to convert "int" to "Graph_lib::Point" for x_max() and expected a ')' for the comma after the first 70.
What are the constructors of Point?
Here is the Point header:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#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; }
	};


I uncommented the boldfaced line and no longer have header errors.
Thank you very much. This gets me a step closer to getting the program to run. I know I will have other errors when I compile the C++ files for Window and Graph.

However, once again, thank you very much.
Topic archived. No new replies allowed.