Aggregate has incomplete data type?

Following suggestions I received on this site, I've been trying to work with multiple files and applying OOP concepts. When trying to compile, the following warning appears:

Aggregate "App app" has incomplete data type and cannot be defined.

Here are the files:

Main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "nave_v2.h"

int main()
{
	App app;
	while (app.IsOpen())
	{
		app.Clear();
		app.Display();
		app.GetKey();
	}

	return 0;
}


main.h

1
2
3
4
5
6
#ifndef CLASSES
#define CLASSES

class App;

#endif 


classes.cpp

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
#include "SFML/Graphics.hpp"

class App
{
	sf::RenderWindow window;
	sf::Event keyPress;

	int SCREEN_WIDTH;
	int SCREEN_HEIGHT;
	int SCREEN_DEPTH;

	public:

		App()
		{
			SCREEN_WIDTH = 800;
			SCREEN_HEIGHT = 600;
			SCREEN_DEPTH = 32;
			window.Create(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH), "Window");
		}

		void Display()
		{
			window.Display();
		}

		void Clear()
		{
			window.Clear();
		}

		bool IsOpen()
		{
			return window.IsOpened();
		}

		void ProcessKey()
		{
			switch (keyPress.Key.Code)
			{
				case sf::Key::Escape:
					window.Close();
					break;
				default:
					break;
			}
		}

		void GetKey()
		{
			window.GetEvent(keyPress);
			if (keyPress.Type == sf::Event::KeyPressed) ProcessKey();
		}

};


I'm not sure what incomplete data type means. Reading around, I thought it had something to do with the void functions, but when I changed them all to int and had them return 0, the compiler reported the same error.

If I use a single file, the program compiles OK.

Any replies will be appreciated.
Class definitions go in header files. The compiler is saying that it doesn't know enough about App to let you create one.

It's seeing something like this:
1
2
3
4
5
class App; // forward declaration only (an incomplete type)

int main() {
    App app; // ERROR!
...


It needs to see:
1
2
3
4
5
class App { /* what an App is */ };

int main() {
    App app; // Oh yeah, an App.  No problem.
...


Remember that header files are just inserted verbatim by the preprocessor.
Last edited on
Thanks, it works now :D

But I thought that the point of header files was to link classes.cpp and main.cpp as if they were the same file...

I'll keep on reading. Thanks again!
Topic archived. No new replies allowed.