classes, includes, and... syntax errors?

I've dabbled in and out of programming for a few years, and I'm just starting to get back into c/c++...

I started writing a bunch of code, and all of a sudden, when trying to reference to a class inside another class I'm getting syntax errors and missing type specifier errors.

I'm pretty sure my syntax is good, and I can (and do) include, and objectify all classes in the source code. I have also, included and externally referenced objects of [boot in operations] [render in boot] [events in operations] [render in operations]. But when I try to reference operations in events.h i get this issue.

basically what I'm trying to do is arrange my boot/runtime/event handler/render functions all in different classes. Before I even coded anything other than includes and objects, I get issues.

source.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <vector>
#include "sdl.h"
#include "sdl_ttf.h"

#include "operations.h"
#include "boot.h"
#include "render.h"
#include "events.h"


operations op;
boot bt;
render ren;
events ev;

using namespace std;

int main(int args, char* argc[])
{

	return 0;
}


Problem (events.h):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#pragma once

#include <iostream>
#include "SDL.h"

#include "operations.h"

//extern operations op;

class events
{
public:
	events(void);
	~events(void);
};


The commented code puts 8 different errors in my debugger, and all objects of operation become syntax errors.

Operations :

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
//header file


#pragma once

#include "sdl.h"
#include "SDL_ttf.h"
#include <iostream>

#include "boot.h"
#include "events.h"

extern boot bt;

using namespace std;


class operations
{
public:
	operations(void);
	~operations(void);
};


//cpp file
#include "operations.h"


operations::operations(void)
{
}


operations::~operations(void)
{
}


Errors (doesn'[t tell me much aside from it not recognizing class objects):

1
2
3
4
5
6
7
8
Error	1	error C2146: syntax error : missing ';' before identifier 'op'	c:\users\~~~~\documents\visual studio 2012\projects\demo1\demo1\events.h	8	1	Demo1
Error	2	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\~~~~\documents\visual studio 2012\projects\demo1\demo1\events.h	8	1	Demo1
Error	3	error C2146: syntax error : missing ';' before identifier 'op'	c:\users\~~~~\documents\visual studio 2012\projects\demo1\demo1\source.cpp	12	1	Demo1
Error	4	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\~~~~\documents\visual studio 2012\projects\demo1\demo1\source.cpp	12	1	Demo1
Error	5	error C2086: 'int op' : redefinition	c:\users\~~~~\documents\visual studio 2012\projects\demo1\demo1\source.cpp	12	1	Demo1
Error	6	error C2146: syntax error : missing ';' before identifier 'op'	c:\users\~~~~\documents\visual studio 2012\projects\demo1\demo1\events.h	8	1	Demo1
Error	7	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\~~~~\documents\visual studio 2012\projects\demo1\demo1\events.h	8	1	Demo1


what am I doing wrong?
Last edited on
You almost have a cyclic inclusion problem. Your events.h includes operator.h, but operation.h includes events.h. The way to fix it would normally be to forward declare something, but in your case your operations class doesn't even need your events class, so just remove line 11 in your operation.h file.

If you do actually need it, then you can forward declare. As long as you aren't storing/returning an instance of that class, you can just go class operations;, and then include its header in the source file. The same goes for events.
Topic archived. No new replies allowed.