VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: [1] ]


[ Next Thread | Previous Thread | Next Message | Previous Message ]

Date Posted: 13:34:45 01/06/04 Tue
Author: kai
Subject: Re: GLUT keyboardfunc in klassen
In reply to: grumble 's message, "GLUT keyboardfunc in klassen" on 06:59:51 04/04/03 Fri

glut ist c und dein classe ist c++.
bei c++ ist der erste parameter ein impliziter zeiger auf die instanz der klasse zu der die methode gehört. den gibst du nie an, er ist aber vorhanden. glut übergibt diesen this-zeiger nicht. dann kommt es zu der fehlermeldung.
workaround:
statische methoden für die callbacks registrieren
static void drawcb()...

hat den nachteil, dass du nun nichtmehr weisst welche instanz du brauchst:
also brauchst du eine statische variable(eine liste oder wie auch immer) die einen this zeiger enthält.

das ganze sieht dann ungefähr so aus:
---------------------------------------------
class GLUT_CLASS{
protected:
//implementation nach deinen wünschen...
void keyboard(int key,int x,int y);
public:
GLUT_CLASS(){
if(!me)
me=this;
.....
}
static GLUT_CLASS *me;

static void keyboardcallback(int,int,int);
}

GLUT_CLASS GLUT_CLASS::me=0;
void GLUT_CLASS::keyboardcallback(int key,int x,int y){
if(me)
me->keyboard(key,x,y);
}
------------------------------------------------
natürlich hat diese klasse eine einzige instanz, sonst musst du herumspielen und deine verschiedenen instanzen unter einen hut bringen(irgendwie scedulen); dann kannst du mit
glutKeyboardFunc(&(GLUT_CLASS::keyboardcallback));
deine keyboardfunction registrieren(egal wo).
callbacks bei c++ sind klassen bei c funktionen;
wer sag c++ ist eine erweiterung zu c, müsste spätestens hier zum nachdenken kommen.
mfg kai

[ Next Thread | Previous Thread | Next Message | Previous Message ]

[ Contact Forum Admin ]


Forum timezone: GMT-8
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.