PDA

View Full Version : classes



dirtmaster
06-13-2001, 10:13 AM
I've been trying to add a class to my OpenGL program and this is the code I use to declare and define the class:

class Shell
{
public:
shootCannon(int velocity);
};

void Shell::shootCannon (int velocity)
{

shellVelocity = velocity;
glColor3f(1.0f, 0.0f, 0.0f);
//Draw projectile
glPushMatrix();
glTranslatef(0.0f, 10.0f, 0.0f);
glTranslatef(moveShell, 0.0f, 0.0f);
glBegin(GL_QUADS);

glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,5.0f,0.0f);
glVertex3f(5.0f,5.0f,0.0f);
glVertex3f(5.0f,0.0f,0.0f);

glVertex3f(5.0f, 0.0f, 0.0f);
glVertex3f(5.0f,5.0f,0.0f);
glVertex3f(5.0f,5.0f,-5.0f);
glVertex3f(5.0f,0.0f,-5.0f);

glVertex3f(5.0f, 0.0f, -5.0f);
glVertex3f(5.0f,5.0f,-5.0f);
glVertex3f(0.0f,5.0f,-5.0f);
glVertex3f(0.0f,0.0f,-5.0f);

glVertex3f(0.0f, 0.0f, -5.0f);
glVertex3f(0.0f,5.0f,-5.0f);
glVertex3f(0.0f,5.0f,0.0f);
glVertex3f(0.0f,0.0f,0.0f);

glVertex3f(0.0f, 5.0f, 0.0f);
glVertex3f(0.0f,5.0f,-5.0f);
glVertex3f(5.0f,5.0f,-5.0f);
glVertex3f(5.0f,5.0f,0.0f);

glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f,0.0f,-5.0f);
glVertex3f(5.0f,0.0f,-5.0f);
glVertex3f(5.0f,0.0f,0.0f);

glEnd();
glPopMatrix();

}

when I compile I get these errors:
Compiling...
Triangle.c
C:\Anthony\OpenGLSB2E\myfiles\Triangle\Triangle.c( 29) : error C2061: syntax error : identifier 'Shell'

C:\Anthony\OpenGLSB2E\myfiles\Triangle\Triangle.c( 29) : error C2059: syntax error : ';'

C:\Anthony\OpenGLSB2E\myfiles\Triangle\Triangle.c( 30) : error C2449: found '{' at file scope (missing function header?)

C:\Anthony\OpenGLSB2E\myfiles\Triangle\Triangle.c( 33) : error C2059: syntax error : '}'
Error executing cl.exe.

Triangle.exe - 4 error(s), 0 warning(s)

The four errors correspond to the class declaration and not the function definition.
Please help!!!!

Nutty
06-13-2001, 11:14 AM
triangle.c??

Would the compiler be compiling it as a C file perchance?

rename to triangle.cpp and try again.

Nutty


Just in case I was being too vague, the c language does not allow classes, thats C++. Most compilers take the extension of the source file, to determine what compiler to use on it.


[This message has been edited by Nutty (edited 06-13-2001).]

Deiussum
06-13-2001, 11:22 AM
Are you compiling multiple files? If not is the class declaration in triangle.c before you actually try to create a Shell object?

It looks like you are trying to create an object of the class before it is actually declared.

Actually, just saw Nutty's response. (He must have replied just as I hit reply) I think he's probably right. The compiler probably is trying to compile it as C instead of C++ since it is named .c. http://www.opengl.org/discussion_boards/ubb/smile.gif

DaViper
06-15-2001, 02:22 AM
Originally posted by dirtmaster:
I've been trying to add a class to my OpenGL program and this is the code I use to declare and define the class:

class Shell
{
public:
shootCannon(int velocity);
};




class Shell
{
public:
void shootCannon(int velocity);
};


this seems more corrext to me, but not sure if this is the prob...

Chris

bsperlin
06-15-2001, 04:34 AM
Good morning,
Does the class have a constructor? Are you going to do some initializing in the constructor?
Barry