Please help with classes in openGL
I''m trying to add a class to my modified lesson14 code. It doesn''t work though. Here''s the section:
class myclass{
private:
char mydata[6];
public:
void printclass(){mydata[0]=''h''; glPrint(mydata);};
};
int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); glTranslatef(-7.5f,-8.0f,-22.0f); glColor3f(0.5f,0.0f,0.5f);
myclass.printclass();
return TRUE;
}
I get this error message:
--------------------Configuration: lesson14 - Win32 Debug--------------------
Compiling...
3dguys.cpp
C:\My Documents\lesson14\lesson14.cpp(546) : error C2146: syntax error : missing '';'' before identifier ''myclass''
C:\My Documents\lesson14\lesson14.cpp(546) : error C2501: ''GLclass'' : missing storage-class or type specifiers
C:\My Documents\lesson14\lesson14.cpp(546) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
Lesson14.exe - 3 error(s)
Thanks!
oops! Here''s the real error message:
C:\My Documents\lesson14\lesson14.cpp(566) : error C2143: syntax error : missing '';'' before ''.''
C:\My Documents\lesson14\lesson14.cpp(566) : error C2143: syntax error : missing '';'' before ''.''
The last one was when I tried using GLclass =) Guess there''s no such thing.
C:\My Documents\lesson14\lesson14.cpp(566) : error C2143: syntax error : missing '';'' before ''.''
C:\My Documents\lesson14\lesson14.cpp(566) : error C2143: syntax error : missing '';'' before ''.''
The last one was when I tried using GLclass =) Guess there''s no such thing.
void printclass(){mydata[0]=''h''; glPrint(mydata);};
There should be no semicolon at the end of this line. See if that helps.
Andrew
First of all cut of the semicolon '';'' at the line
void printclass(){mydata[0]=''h''; glPrint(mydata);};
and change in
void printclass(){mydata[0]=''h''; glPrint(mydata);}
Then you can''t refer to the name of the class to invoke its method but you have to create an instance of the class.
I mean, No
myclass.printclass();
But
myclass mc;
..........
..........
..........
mc.printclass();
Hope I was able to help you....
void printclass(){mydata[0]=''h''; glPrint(mydata);};
and change in
void printclass(){mydata[0]=''h''; glPrint(mydata);}
Then you can''t refer to the name of the class to invoke its method but you have to create an instance of the class.
I mean, No
myclass.printclass();
But
myclass mc;
..........
..........
..........
mc.printclass();
Hope I was able to help you....
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement