Error Using FLTK and C++

Write your question here.
Why am I getting this error message:

1>------ Build started: Project: C12Test, Configuration: Debug Win32 ------
1>  fltk.cpp
1>c:\users\phztfte1\documents\visual studio 2013\projects\c12test\c12test\fltk.cpp(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I am in Chapter 12 of Bjarne Stroustrup Programming, Principles and Practice Using C++. If you need more information, please let me know.

Here is my code:
1
2
3
4
5
6
7
8
9
10
#include "fltk.h"
#include "Window.h"

main()
{
	Fl_Window window(200, 200, "Window title");
	Fl_Box box(0, 0, 200, 200, "Hey, I mean, Hello, World!");
	window.show();
	return Fl::run();
}


The program has several header files, but here is the header file I think the problem is in:
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
#ifndef WINDOW_GUARD
#define WINDOW_GUARD 1

#include "fltk.h"

#include "std_lib_facilities.h"

#include "Point.h"
//#include "GUI.h"

namespace Graph_lib {

	class Shape;	// "forward declare" Shape
	class Widget;

	class Window : public Fl_Window {
	public:
		Window(int w, int h, const string& title);			// let the system pick the location
		Window(Point xy, int w, int h, const string& title);	// top left corner in xy
		virtual ~Window() { }

		int x_max() const { return w; }
		int y_max() const { return h; }

		void resize(int ww, int hh) { w = ww, h = hh; size(ww, hh); }

		void set_label(const string& s) { label(s.c_str()); }

		void attach(Shape& s);
		void attach(Widget& w);

		void detach(Shape& s);	// remove s from shapes 
		void detach(Widget& w);	// remove w from window (deactivate callbacks)

		void put_on_top(Shape& p);	// put p on top of other shapes

	protected:
		void draw();

	private:
		vector<Shape*> shapes;	// shapes attached to window
		int w, h;					// window size

		void init();
	};

	int gui_main();	// invoke GUI library's main event loop

	inline int x_max() { return Fl::w(); }	// width of screen in pixels
	inline int y_max() { return Fl::h(); }	// height of screen in pixels

}
#endif 
Last edited on
Could you provide your code please? It sounds like you might be declaring main() without a type or something like that but unless we have code, we can't look from problems in it.
It's as shadowmouse suspected...

C++ needs

int main() {

You're missing the int return type.

(By default GCC let's you get away with this C-ism (assuming the return type of a function will default to int) with a warning. But the Microsoft Visual Studio C++ compiler does not.)

Andy

PS Can't see any (obvious) errors in the header file!?
Last edited on
On looking at the code you posted, I stand by my previous statement. You have to declare main() as int main()
shadowmouse, andywestken,

Thank you for the response. It was the missing int. My program works. I feel like kicking myself for making such an egregious error. I looked everywhere else but not what was staring at me. I am human after all.

Thank you.
I feel like kicking myself ...

Don't!

As you say, you're only human. And sometimes the "obvious" is the least obvious.

In my last job I made the same "obvious" mistake about once a month (just long enough to forget I'd done before, it till I tracked it down yet again!)

Andy
Topic archived. No new replies allowed.