1Danke
ERLEDIGT
NEIN
NEIN
ANTWORTEN
4
4
ZUGRIFFE
250
250
EMPFEHLEN
-
Ich hab das Problem das eine überladene Funktion bei mir nicht funktioniert.
Der Code sieht folgendermaßen aus:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void drawText(FONTSTYLE fontStyle, int x, int y, int r, int g, int b, int a, const char *text, ...) { D3DCOLOR fontColor = D3DCOLOR_ARGB(a, r, g, b); drawText(fontStyle, x, y, fontColor, text); } //this works fine.. void drawText(FONTSTYLE fontStyle, int x, int y, D3DCOLOR fontColor, const char *text, ...) { RECT rct; rct.left = x; rct.top = y; rct.right = rct.left + 300; rct.bottom = rct.top + 200; va_list va_alist; char logbuf[80] = {0}; va_start(va_alist, text); _vsnprintf(logbuf + strlen(logbuf), sizeof(logbuf) - strlen(logbuf), text, va_alist); va_end(va_alist); getFontByConst(fontStyle)->DrawText(NULL, logbuf, -1, &rct, 0, fontColor); }
Wenn ich die obere funktion aufrufe klappt es nicht. Da die variablen parameter (representiert mit ...) nicht übergeben werden nehme ich an
Wenn ich die untere funktion direkt aufrufe ist alles super.
-
29.08.10 17:00 #2Technologien
(Gute) Grundkenntnisse: HTML, CSS
Fortgeschrittene-Kenntnisse: C++/Qt, C# (WinForms, Webservice), SQL
-
Der code crasht die ganze applikation. Keine Fehlermeldung zu sehen.
Ich denke mal der compiler weiß nicht wie er damit umgehen muss wenn eine Funktion eine variable argumentenliste enthält und diese dann an eine andere funktion weiter gegeben werden muss.
Wenn ich den drawText aufruf in drawText ersetzte mit dem eigentlichen code, dann funktionert es.
So:
Code :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
void drawText(FONTSTYLE fontStyle, int x, int y, int r, int g, int b, int a, const char *text, ...) { D3DCOLOR fontColor = D3DCOLOR_ARGB(a, r, g, b); RECT rct; rct.left = x; rct.top = y; rct.right = rct.left + 300; rct.bottom = rct.top + 200; va_list va_alist; char logbuf[80] = {0}; va_start(va_alist, text); _vsnprintf(logbuf + strlen(logbuf), sizeof(logbuf) - strlen(logbuf), text, va_alist); va_end(va_alist); getFontByConst(fontStyle)->DrawText(NULL, logbuf, -1, &rct, 0, fontColor); } //this works fine.. void drawText(FONTSTYLE fontStyle, int x, int y, D3DCOLOR fontColor, const char *text, ...) { RECT rct; rct.left = x; rct.top = y; rct.right = rct.left + 300; rct.bottom = rct.top + 200; va_list va_alist; char logbuf[80] = {0}; va_start(va_alist, text); _vsnprintf(logbuf + strlen(logbuf), sizeof(logbuf) - strlen(logbuf), text, va_alist); va_end(va_alist); getFontByConst(fontStyle)->DrawText(NULL, logbuf, -1, &rct, 0, fontColor); }
Aber ich wollte ja eigenltich ein paar Zeilen einsparen, indem ich einfach die überladene drawText methode aufrufe. So hab ich den code quasi doppelt drin.
-
„Gib einem Menschen einen Fisch, und er wird für einen Tag satt. Lehre ihn Fischen, und er wird ein Leben lang satt.“
“For every complex problem, there is an answer that is short, simple and wrong.”
“Pessimism is safe, but optimism is a lot faster!”
Aktuelles Coding Quiz: #17 - Wörter kreuz und quer
-
Klappt, danke matthias =)
Ähnliche Themen
-
C Konsolenanwenung, Übergabe von Argumenten
Von eternitysoft im Forum C/C++Antworten: 3Letzter Beitrag: 20.05.10, 13:15 -
Probleme bei Uebergabe von Argumenten > 15 Bit in Bison?
Von Chris76 im Forum C/C++Antworten: 1Letzter Beitrag: 09.06.08, 12:19 -
Default Werte von Argumenten in Funktionen
Von port29 im Forum PHPAntworten: 2Letzter Beitrag: 31.03.08, 13:47 -
Abfrage von Datenbanken mit meheren Argumenten
Von darknet im Forum PHPAntworten: 3Letzter Beitrag: 23.04.05, 20:44 -
Funktion mit variabler Anzahl von Argumenten
Von andreassin im Forum Javascript & AjaxAntworten: 2Letzter Beitrag: 21.09.04, 19:00





Zitieren

Du rufst in der ersten Überladung von drawText nämlich die zweite Überladung ohne die variablen Argumente auf. Da müsstest du genau wie beim Aufruf von _vsnprintf mit va_start und va_end arbeiten.
Login





