What do these errors mean?

I'm getting weird errors I don't understand with this program.
This program is the second part in a three-part assignment. So it's not meant to work, but it IS meant to compile.
Part of the assignment was also to have two separate files, a normal code file and a header file. So that's why there's two.
So, what do these errors mean?


abs9166@puss:/tmp1/abs9166/Desktop$ g++ program5.cpp sketch.h -lGL -lGLU -lglut -lm
In file inclded from program5.cpp:5:0:
sketch.h:33:8: error: making 'n' static [-fpermissive]
sketch.h:33:8: error: ISO C++ forbids in-class initialization of non-const static member 'n'
program5.cpp:46:49: error: 'y1' is not a type
program5.cpp: In member function 'void Sketch::CreateObject(int, int, int, int):
program5.cpp:51:34: error: invalid conversion from 'double (*)(double)throw ()' to 'int' [-fpermissive]
program5.cpp:53:34: error: invalid conversion from 'double (*)(double)throw ()' to 'int' [-fpermissive]
program5.cpp: In member function 'void Sketch::UpdateObject(int, int)':
program5.cpp:82:22: error: 'struct Object' has no member named 'toolType'
program5.cpp:96:8: error: jump to case label [-fpermissive]
program5.cpp:92:8: error:     crosses initialization of 'int r'
program5.cpp:91:8: error:     crosses initialization of 'int y2'
program5.cpp:90:8: error:     crosses initialization of 'int x2'
program5.cpp:89:8: error:     crosses initialization of 'int y1'
program5.cpp:88:8: error:     crosses initialization of 'int x1'
sketch.h:33:8: error: ISO C++ forbids initialization of member 'n' [-fpermissive]
sketch.h:33:8: error: making 'n' static [-fpermissive]
sketch.h:33;8: error: ISO C++ forbids in-class initialization of non-const static member 'n'
abs9166@puss:/tmp1/abs9166/Desktop$


This is the main file.
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
  #include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

#include "sketch.h"

#include <string>
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;

#define PI 3.1415926536

#define WIDTH    	700
#define HEIGHT   	600

#define MENUWIDTH 	100
#define BOXHEIGHT	(HEIGHT/NCOLORS)

#define DSLEFT    	MENUWIDTH
#define DSRIGHT  	WIDTH
#define DSBOTTOM  	0
#define DSTOP     	HEIGHT

#define NCOLORS 	8

#define RGBRED 		1, 0, 0
#define	RGBGREEN	0, 1, 0
#define RGBBLUE		0, 0, 1
#define RGBYELLOW	1, 1, 0
#define RGBMAGENTA	1, 0, 1
#define RGBCYAN		0, 1, 1
#define RGBBLACK	0, 0, 0
#define RGBWHITE	1, 1, 1

#define R		0
#define G		1
#define B		2

Sketch sketcher;

static float colormenu[8][3] = {{RGBRED}, {RGBGREEN}, {RGBBLUE}, {RGBYELLOW}, {RGBMAGENTA}, {RGBCYAN}, {RGBWHITE}, {RGBBLACK}};

//Line
void Sketch::CreateObject(int c, int t, int x1, y1)
{
	objects[n].colortype=c;
	objects[n].tooltype=t;
	objects[n].tool.endpoints.pt1.x=x1;
	objects[n].tool.endpoints.pt1.y=y1;
	objects[n].tool.endpoints.pt2.x=x1;
	objects[n].tool.endpoints.pt2.y=y1;
	n++;
}

//Rectangle
void Sketch::CreateObject(int c, int t, int x1, int y1, int x2, int y2)
{
	objects[n].colortype=c;
	objects[n].tooltype=t;
	objects[n].tool.endpoints.pt1.x=x1;
	objects[n].tool.endpoints.pt1.y=y1;
	objects[n].tool.endpoints.pt2.x=x2;
	objects[n].tool.endpoints.pt2.y=y2;
	n++;
}

//Circle
void Sketch::CreateObject(int c, int t, int r, int x1, int y1)
{
	objects[n].colortype=c;
	objects[n].tooltype=t;
	objects[n].tool.circle.radius=r;
	objects[n].tool.circle.center.x=x1;
	objects[n].tool.circle.center.y=y1;
	n++;
}

void Sketch::UpdateObject(int _x, int _y)
{
	switch(objects[n-1].toolType)
	{
		case 0:
		case 1:
		case 2:
		case 3:
			int x1=objects[n-1].tool.circle.center.x;
			int y1=objects[n-1].tool.circle.center.y;
			int x2=_x;
			int y2=_y;
			int r=sqrt(pow(x2-x1,2)+pow(y2-y1,2));
			objects[n-1].tool.circle.radius=r;
			cout<<"Circle is updated"<<endl;
			break;
		case 4:
			objects[n-1].tool.endpoints.pt2.x=_x;
			objects[n-1].tool.endpoints.pt2.y=_y;
			cout<<"Line/Rect is updated"<<endl;
			break;			
	}
}

void Sketch::Load()
{
	string filename;
	ifstream fin;
	cout<<"Load: ";
	cin>>filename;
	fin.open(filename.c_str());
	if (fin.is_open())
	{		
		while (fin.good())
		{
			fin>>n;
			for(int i=0; i<n; i++)
			{
				fin>>objects[i].colortype;
				fin>>objects[i].tooltype;
				if(objects[i].tooltype==2 || objects[i].tooltype==3)
				{
				  fin>>objects[i].tool.circle.center.x;
				  fin>>objects[i].tool.circle.center.y;
				  fin>>objects[i].tool.circle.radius;
				}
				else
				{
				  fin>>objects[i].tool.endpoints.pt1.x;
				  fin>>objects[i].tool.endpoints.pt1.y;
				  fin>>objects[i].tool.endpoints.pt2.x;
				  fin>>objects[i].tool.endpoints.pt2.y;
				}
			}
		}
	}
	else{cout<<"Load failed";}
}

void Sketch::Save()
{
	string filename;
	ofstream fout;
	cout<<"Save as: ";
	cin>>filename;
	fout.open(filename.c_str());
	if(fout.is_open())
	{
		fout<<n<<" ";
		for(int i=0; i<n; i++)
		{
			fout<<objects[i].colortype<<" "<<objects[i].tooltype<<" ";
			if(objects[i].tooltype==2 || objects[i].tooltype==3)
			{
				fout<<objects[i].tool.circle.center.x<<" ";
				fout<<objects[i].tool.circle.center.y<<" ";
				fout<<objects[i].tool.circle.radius<<" ";
			}
			else
			{
				fout<<objects[i].tool.endpoints.pt1.x<<" ";
				fout<<objects[i].tool.endpoints.pt1.y<<" ";
				fout<<objects[i].tool.endpoints.pt2.x<<" ";
				fout<<objects[i].tool.endpoints.pt2.y<<" ";
			}
		fout<<endl;
		}
	}
	
}

void Sketch::Clear()
{
	n=0; 
	glutPostRedisplay;
}

void Sketch::drawRectangle(int index, GLint type)
{
	int c = objects[index].colortype;
	int x1 = objects[index].tool.endpoints.pt1.x;
	int y1 = objects[index].tool.endpoints.pt1.y;
	int x2 = objects[index].tool.endpoints.pt2.x;
	int y2 = objects[index].tool.endpoints.pt2.y;

	glColor3f(colormenu[c][R], colormenu[c][G], colormenu[c][B]);

	glBegin(type);
		glVertex2i(x1,y1);
		glVertex2i(x1,y2);
		glVertex2i(x2,y2);
		glVertex2i(x2,y1);
	glEnd();
}


void Circle(GLint type)
{
	int i=36;                 
  	float angle;
  	float anglecounter= 2*PI/i; 
        
   	glBegin(type);
    	for(int k=0; k<i; k++)
	{
      		angle = k*anglecounter;
      		glVertex2f(cos(angle),sin(angle));
    	}
  	glEnd(); 
}

void Sketch::drawCircle(int index, GLint type)
{
	int c=objects[index].colortype;
	int x=objects[index].tool.circle.center.x;
	int y=objects[index].tool.circle.center.y;
	float r=objects[index].tool.circle.radius;

	glColor3f(colormenu[c][R], colormenu[c][G], colormenu[c][B]);

	glPushMatrix();
		glTranslatef(x,y,0);
		glScalef(r,r,1);
		Circle(type);
	glPopMatrix();
}

void Sketch::drawLine(int index)
{
	int c=objects[index].colortype;
	int x1=objects[index].tool.endpoints.pt1.x;
	int y1=objects[index].tool.endpoints.pt1.y;
	int x2=objects[index].tool.endpoints.pt2.x;
	int y2=objects[index].tool.endpoints.pt2.y;

	glColor3f(colormenu[c][R], colormenu[c][G], colormenu[c][B]);

	glBegin(GL_LINE_LOOP);
		glVertex2i(x1,y1);
		glVertex2i(x2,y2);
	glEnd();	
}

void Sketch::draw()
{
	for(int i=0; i<n; i++)
	{
		switch(objects[i].tooltype)
		{
			case 0: drawRectangle(i, GL_LINE_LOOP);
				break;

			case 1: drawRectangle(i, GL_POLYGON);
				break;

			case 2: drawCircle(i, GL_LINE_LOOP);
				break;

			case 3: drawCircle(i, GL_POLYGON);
				break;

			case 4: drawLine(i);
				break;

			case 5: drawLine(i);
				break;
		}
	}
	glutPostRedisplay();
}


This is the header file.
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
#  include <GL/gl.h>
#  include <GL/glu.h>
#  include <GL/glut.h>

struct Point
{int x,y;};

struct EndPoint
{Point pt1, pt2;};
	
struct Circle
{
	Point center;
	int radius;
};

union Tool
{
	EndPoint endpoints;
	Circle circle;
};

struct Object
{
	short int colortype;
	short int tooltype;
	Tool tool;
};

class Sketch
{
	Object objects[10000];
	int n=0;
		public:
		void CreateObject(int, int, int, int);
		void CreateObject(int, int, int, int, int);
		void CreateObject(int, int, int, int, int, int);
		void UpdateObject(int, int);
		void Save();
		void Load();
		void Clear();
		void drawRectangle(int, GLint);
		void drawCircle(int, GLint);
		void drawLine(int);
		void draw();	
};


Please help me! I've been having a lot of trouble with this program and I would like to be finished with it today. I really appreciate the help!
This should take care of some of those...

You're missing the type for y1 here.
program5.cpp:46:49: error: 'y1' is not a type
void Sketch::CreateObject(int c, int t, int x1, y1)

Spelling difference here.
program5.cpp:82:22: error: 'struct Object' has no member named 'toolType'
short int tooltype;


Edit:

error: ISO C++ forbids in-class initialization of non-const static member 'n'

See this previous answer for a similar problem.
http://www.cplusplus.com/forum/beginner/100701/


program5.cpp:92:8: error:     crosses initialization of 'int r'

See this thread over on StackOverflow
http://stackoverflow.com/questions/2392655/what-are-the-signs-of-crosses-initialization
Last edited on
Ahh, alright I see. Thank you very much! Those are very helpful.
Topic archived. No new replies allowed.