Unsure about Errors in OpenGL and classes

I am getting errors and I am unsure how too fix them,I have a circle class and a triangle class and the triangle one was working until I created the circle one and now the triangle class has started too pop up with errors, any help would be appreciated.

This is the header file for the triangle class :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<glut.h> 
#include"shape.h" 

class triangle: public shape 
{ 
public: 
 triangle(float ix, float iy, float iwidth, float iheight) 
          :shape(ix, iy) 
 { 
  width = iwidth;  height = iheight; 
 }
 void show(); // Defined below. 
private: 
float width, height; 
}; 


This is the triangle code:

1
2
3
4
5
6
7
8
9
10
11
12
#include<glut.h> 
#include"shape.h"
#include"triangle.h"

void triangle::show(){ 
 shape::show(); 
 glBegin(GL_LINE_LOOP); 
  glVertex2f(x, y); 
  glVertex2f(x+width, y); 
  glVertex2f(x+width/2, y+height); 
 glEnd(); 
} 


And this is the main function and display:

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
#include<glut.h> 
#include"shape.h" 
#include"triangle.h"
#include"circle.h"
#include<cmath>



	circle c1(0.2, 0, 0);
	triangle t(0, 0.3, 0.5, 0.4);

	void display()
	{ 
		glClear(GL_COLOR_BUFFER_BIT); 
		c1.setColour(0, 0, 1);
		c1.move(0.0000001, 0);
		c1.show();
		t.setColour(0, 0, 1); 
		t.move(0.0001, -0.0002); 
		t.show(); 
		glFlush(); 
	} 

	int main(int argc, char **argv) 
	{ 
		glutInit(&argc, argv); 
		glutCreateWindow("Simple Shapes"); 
		glClearColor(1, 0, 0, 0.5); 
		glutDisplayFunc(display); 
		glutIdleFunc(display); 
		glutMainLoop(); 
		return 0; 
	}


It says I am redefining the triangle class in the header file and im quite sure this is causing the rest of the errors but dont know why this one is coming up, thanks guys.
Your cpp file is including shape
Your cpp file is also including triangle, which includes shape again.

therefore shape is being included twice, which defines the class twice.

You need to guard your headers. See this link:
http://www.cplusplus.com/forum/articles/10627/#msg49679
get rid of your glut.h and shape.h in your triangle.cpp file, that may fix it.

and then of course you have to do the same with main.
Last edited on
thanks guys, just got it , i also accidentally had copied the triangle header into one of my circle classes, that was just sloppy, but its fixed now even though my circle isnt drawing *sigh* time too look into that :)
Topic archived. No new replies allowed.