• Advertisement

Archived

This topic is now archived and is closed to further replies.

Please help with classes in openGL

This topic is 6483 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites


void printclass(){mydata[0]=''h''; glPrint(mydata);};

There should be no semicolon at the end of this line. See if that helps.


Andrew

Share this post


Link to post
Share on other sites
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....

Share this post


Link to post
Share on other sites

  • Advertisement