include problem

kk so im making a project and i cannot get over this problem. Visual studio 2011 keeps throwing:
1>e:\fusion gl\fusion gl\accessories.h(8): error C2143: syntax error : missing ';' before '*'
1>e:\fusion gl\fusion gl\accessories.h(8): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\fusion gl\fusion gl\accessories.h(8): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// explorer.h
#pragma once
//includes
#include "accessories.h"
// thats where i think the problem is
// more includes
class Explorer{
// methods that are not important
};

// accessories.h
#pragma once

#include "explorer.h"
#include "program.h"

class AccessoriesWin:public Program{
     Explorer *explorer; // it says here "syntax error:missing ';' before '*'"
// other stuff
};

i have tried using typedef, extern. Im stuck. I need to be able to call functions that are in the Explorer class. I cannot create a new one, the reason is complex, as i would have to explain the full structure of my project.
Last edited on
closed account (zb0S216C)
The closing brace of a class requires a semi-colon immediately after it. For example:

1
2
3
class Object 
{
}; // <-- Here 

However, there's 1 exception: Object declarations. For instance:

1
2
3
class Object
{
} new_object; // <-- The semi-colon still should be here, regardless of form. 

In this code, new_object is an instantiation of Object.

Wazzak
Last edited on
sorry i forgot, but there are actually semi colons after each class definition
closed account (zb0S216C)
Can you post lines 1:8 from accessories.h?

Wazzak
Last edited on
1
2
3
4
5
6
7
8
#pragma once
#include "explorer.h"
#include "program.h"
#include "textpad.h"

class AccessoriesWin: public Program{
private:
	Explorer *explorer;
closed account (zb0S216C)
Can you post the implementation of Explorer? This goes deeper than expected.

Wazzak
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
// shell of explorer, with all functions complete it was over 400 lines + everything in explorer works like it should
#pragma once
#include <vector>
#include <string>
#include <fstream>
#include "Graphics.h"
#include "drawableItem.h"
#include "Window.h"
#include "color.h"
#include "taskbarAndmenu.h"
#include "themeFile.h"
#include "tempWin.h"
#include "myFusion.h"
#include "ExploreFile.h"
#include "games.h"
#include "accessories.h"
#include "sysSet.h"
#include "TaskManager.h"
#include "clock.h"

class Explorer{ // pretty much like windows explorer, draws windows, opens directories, draws main items
private:
	Graphic graphic;
	string themePath;
	Clock clock;
	vector<DrawableItem*> Items;
	double R;
	double G;
	double B;
	double A;
	bool ItemFocus;
	bool FocusItemSelected;
	Taskbar taskbar;
	ThemeTextures themetxt;
	bool drawSquare;
	int startSX;
	int startSY;
	int startSXF;
	int startSYF;
	int winPos; // position that windows should be created
	int getPos(){	}
	int findID(int ID){	}
	int inWindow(int X, int Y){	}
	void bringItemFront(int X, int Y){	}
	void bringItemFront(int index){	    }
	void drawBuild(){     }
	int makeID(){	}
	void error(string error){	}
	void drawTint(int x, int y, int h, int w){	}
	void saveColor(){	}
public:
	int NumItems(){    }
	Explorer(){	}
	Explorer(double R, double G, double B, double A, string themePath){	}
	void createWindow(int X, int Y, int W, int H, bool xB, bool minB, bool maxB, string title, Program *n){	}
	void createWindow(int X, int Y, int W, int H, string title, Program *n){	}
	void createWindow(int W, int H, string title, Program *n){	}
	GLint performanceWarning(){	}
	GLint performanceDrop(){	}
	void StartExplorer(){	}
	void MousePress(int X, int Y, int button){	}
	void MouseRelease(int button){    }
	void MouseMotion(int X, int Y, int Xrel, int Yrel){	}
	void key(int key, bool pressed){	}
	void destroyItem(int item){	}
	bool eraseItem(){	}
	void StopExplorer(){	}
	void DrawItems(int FPS){	}
};
Thanks... I feel kinda dumb.

edit: not solved!!! what is making that problem in the first place. I cannot simply declare the Explorer class because i need to use members. What i need to do is when the AccessoriesWin class is made, it is created from an existing instance of a Explorer class, I need to pass "this" to the constructor. later createWindow will be called. I read the article twice.
Last edited on
Sorry, I don't understand you. ¿Could you please provide a minimal setup?
I don't see why 'explorer' needs to include 'accessories'.
explorer must include accessories because an instance of the AccessoriesWin class will be created in Explorer during run time. Im making a GUI, how it works is there is a window class that extends DrawableItem (hence the vector holding DrawableItems). each Window requires a Program(base class) that controls them, thats why AccessoriesWin extends Program, and why createWindow() needs a Program pointer. I need to create a Window from the AccessoriesWin instance. What im trying to do is when an instance of AccessoriesWin is created from an instance of Explorer, is:
1
2
3
Explorer *temp = this;
Program *n = AccessoriesWin(/*other parameters not shown*/, temp);
CreateWindow(100, 100, 100, 100, "Accessories", n);

then from accessories window i want to create more windows, I have another class called Textpad, so from the accessories window ill do something like this
1
2
3
// Explorer explore is defined
Program *n = new TextPad(/*Parameters*/);
explore->CreateWindow(100, 100, "TextPad", n);

You could separate the declaration from the implementation.
So just put the declarations in the header, that way you don't need to include
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//accessories.h
#pragma once
#include "program.h"
class explorer; //forward declaration
class AccessoriesWin: public Program{
  Explorer *explorer;
};

//explorer.h
#pragma once
class Explorer{
//...
};

//explorer.cpp
#include "explorer.h"
#include "accessories.h"
//here both classes are defined. Now we define the methods.
Explorer::Explorer(){
  Program *n = AccessoriesWin(/*other parameters not shown*/, *this);
}


Also check point 7 in the article ('function inlining'), but I think that you better separate the implementation.
that sounds like that might actually cause more problems... The current file has about 17 other classes that are built around how Explorer is currently set up. I'll try other solutions... like just have explorer check if any windows need to be created. have a structure like this
1
2
3
4
5
6
7
8
class CreateWindow{
public: // just use public, nothing else is going to be able to modify values
int X; // if -1 then use the getPos method
int Y; // if -1 then use the getPos method
int W;
int H;
Program *prog;
};

then explorer could make a window with those like this:
1
2
// inside explorer
createWindow(createWIN->X, Y, W, H, prog); //all Parameters do have createWIN-> 
The current file has about 17 other classes that are built around how Explorer is currently set up
Talking about coupling...
All that the user should care is about the interface of the class (the prototype of the methods)
How is it implemented should not affect you, and it will be changed a lot.

The compiler just need to see the members you've got (what is their type), and the prototypes of the methods.
The implementation will be resolved at linking time.
That said, separating definition .h from implementation .cpp should not cause any issues
Topic archived. No new replies allowed.