Classen header (mit SDL)
-
ich hab seit zurzer zeit ein kleines project angefangen
und schon einige header datein geschreiben die klappen und jetzt stehe ich wieder vor einen problem
Colors.h#ifndef __COLORS_H #define __COLORS_H class Colors { SDL_Color color; SDL_Surface *src_bitmap; protected: Colors(Uint8 red,Uint8 green,Uint8 blue,Uint8 alpha,SDL_Surface *src_bitmap2); void set(Uint8 red,Uint8 green,Uint8 blue,Uint8 alpha); void setred(Uint8 red); void setblue(Uint8 blue); void setgreen(Uint8 green); void setalpha(Uint8 alpha); Uint8 getred(); Uint8 getgreen(); Uint8 getblue(); Uint8 getalpha(); }; #endifColors.cpp
#ifndef SDLLIB #define SDLLIB #include <SDL/SDL.h> #include <SDL/SDL_mixer.h> #include <SDL/SDL_image.h> #include <SDL/SDL_ttf.h> #include <SDL/SDL_gfxPrimitives.h> #include <SDL/SDL_rotozoom.h> #include <SDL/SDL_framerate.h> #include <SDL/SDL_imageFilter.h> #endif #include "Colors.h" Colors::Colors(Uint8 red,Uint8 green,Uint8 blue,Uint8 alpha = 255,SDL_Surface *src_bitmap2 = NULL){ color.r=red; color.b=blue; color.g=green; color.unused=alpha; src_bitmap=src_bitmap2; } void Colors::set(Uint8 red,Uint8 green,Uint8 blue,Uint8 alpha = 255){ color.r = red; color.b = blue; color.g = green; color.unused = alpha; if (src_bitmap != NULL){ SDL_SetColors(src_bitmap, &color,0,255); SDL_SetAlpha(src_bitmap, SDL_RLEACCEL, color.unused); } } void Colors::setred(Uint8 red){ color.r = red; if (src_bitmap != NULL){ SDL_SetColors(src_bitmap, &color,0,255); SDL_SetAlpha(src_bitmap, SDL_RLEACCEL, color.unused); } } void Colors::setblue(Uint8 blue){ color.b = blue; if (src_bitmap != NULL){ SDL_SetColors(src_bitmap, &color,0,255); SDL_SetAlpha(src_bitmap, SDL_RLEACCEL, color.unused); } } void Colors::setgreen(Uint8 green){ color.g = green; if (src_bitmap != NULL){ SDL_SetColors(src_bitmap, &color,0,255); SDL_SetAlpha(src_bitmap, SDL_RLEACCEL, color.unused); } } void Colors::setalpha(Uint8 alpha){ color.unused = alpha; if (src_bitmap != NULL){ SDL_SetColors(src_bitmap, &color,0,255); SDL_SetAlpha(src_bitmap, SDL_RLEACCEL, color.unused); } } Uint8 Colors::getred(){return color.r;} Uint8 Colors::getgreen(){return color.g;} Uint8 Colors::getblue(){return color.b;} Uint8 Colors::getalpha(){return color.unused;}Fonts.h
#ifndef __FONTS_H #define __FONTS_H #include <string> using namespace std; #include "Colors.h" class Fonts { string pfad; string name; unsigned int size; bool bold; bool italic; Colors color; TTF_Font *fontg; protected: Fonts(string nam,unsigned int siz); ~Fonts(); void setname(string nam); void setsize(unsigned int siz); void setbold(bool bol); void setitalic(bool itali); void setcolor(Colors colo); string getname(); unsigned int getsize(); bool getbold(); bool getitalic(); Colors getcolor(); }; #endifFonts.cpp
#ifndef SDLLIB #define SDLLIB #include <SDL/SDL.h> #include <SDL/SDL_mixer.h> #include <SDL/SDL_image.h> #include <SDL/SDL_ttf.h> #include <SDL/SDL_gfxPrimitives.h> #include <SDL/SDL_rotozoom.h> #include <SDL/SDL_framerate.h> #include <SDL/SDL_imageFilter.h> #endif #include "Fonts.h" Fonts::Fonts(string nam = "",unsigned int siz = 22): color(new Colors(255,255,255)), bold(false), italic(false), #if defined(WIN32) || defined(__WIN32__) pfad("C:\\WINDOWS\\Fonts"), #elif defined(linux) || defined(__linux__) pfad("/usr/share/fonts/"), #endif size(siz), fontg(TTF_OpenFont(pfad+name , size)) { #if defined(WIN32) || defined(__WIN32__) if (nam == ""){ name = "arial.ttf";}else {name = nam;} #elif defined(linux) || defined(__linux__) if (nam == ""){ name"freefont/FreeSerif.ttf"}else {name = nam;} #endif } Fonts::~Fonts(){delete color;} void Fonts::setname(string nam){name = nam;} void Fonts::setsize(unsigned int siz){size = siz;} void Fonts::setbold(bool bol){bold = bol; if (bold) {TTF_SetFontStyle(fontg,TTF_STYLE_BOLD);}else if (!bold && !italic){TTF_SetFontStyle(fontg,TTF_STYLE_UNDERLINE);}} void Fonts::setitalic(bool itali){italic = itali; if (bold) {TTF_SetFontStyle(fontg,TTF_STYLE_ITALIC);}else if (!bold && !italic) {TTF_SetFontStyle(fontg,TTF_STYLE_UNDERLINE);}} void Fonts::setcolor(Colors colo) {color = colo;} string Fonts::getname(){return name;} unsigned int Fonts::getsize(){return size;} bool Fonts::getbold(){return bold;} bool Fonts::getitalic(){return italic;} Colors Fonts::getcolor(){return color;};fehlermeldung:
1 ..\Fonts.cpp [Warning]nul.gcda' is not a gcov data file ..\\Fonts.cpp In constructorFonts::Fonts(std::string, unsigned int)':
15 ..\Fonts.cpp no matching function for call toColors::Colors(int, int, int)' note ..\\Colors.h:3 candidates are: Colors::Colors(const Colors&) note ..\\Colors.h:3 Colors::Colors(Uint8, Uint8, Uint8, Uint8, SDL_Surface*) 24 ..\\Fonts.cpp cannot convert \std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to `const char*' for argument `1' to `TTF_Font* TTF_OpenFont(const char*, int)'
..\Fonts.cpp In destructorFonts::~Fonts()': 34 ..\\Fonts.cpp type \class Colors' argument given to `delete', expected pointer
..\Makefile.win [Build Error] ["../Neuer Ordner/Fonts.o"] Error 1könnt ihr mir bitte helfen
-
du koenntest dir mal die fehlermeldungen durchlesen und die fehler beheben.
exemplarisches sei hier einer aufgezeigt:no matching function for call to `Colors::Colors(int, int, int)'
naemlich da:
color(new Colors(255,255,255))na sowas, es gibt ja auch nur:
Colors(Uint8 red,Uint8 green,Uint8 blue,Uint8 alpha,SDL_Surface *src_bitmap2);den inhalt der restlichen parameter muss der compiler raten und gibt eine fehlermeldung.
warum du das nicht alleine loesen konntest ist mir jedoch unklar.
-
in colors.cpp
Colors(Uint8 red,Uint8 green,Uint8 blue,Uint8 alpha = 255,SDL_Surface *src_bitmap2 = NULL)
sind standart parameter definirtwen ich das auch bei colors.h definire kommt diese fehlermeldung
14 ..\Colors.cpp default argument given for parameter 4 ofColors::Colors(Uint8, Uint8, Uint8, Uint8, SDL_Surface*)' 8 ..\\Colors.h after previous specification inColors::Colors(Uint8, Uint8, Uint8, Uint8, SDL_Surface*)'
14 ..\Colors.cpp default argument given for parameter 5 ofColors::Colors(Uint8, Uint8, Uint8, Uint8, SDL_Surface*)' 8 ..\\Colors.h after previous specification inColors::Colors(Uint8, Uint8, Uint8, Uint8, SDL_Surface*)'
-
default-parameter in der implementierung zu deklarieren macht keinen sinn weil eine andere implementierung nur deren header einbindet und von diesen parametern also nichts weiss.
die schon bekannten default-parameter aus dem header in der implementierung *nochmal* zu deklarieren macht auch keinen sinn (siehe fehlermeldung).
definiere die parameter also nur im header und ueberlege dir ein buch anzuschaffen, dass die grundlagen von c++ vermittelt.
-
ok hab jetzt die probleme gelöst
aber ein problem ist noch da
bei der syntax überprüfung steht
1 ..\main.cpp [Warning] `nul.gcda' is not a gcov data fileund wenn ich die datei compilire
kommt dieser fehler
..\Makefile.win [Build Error] [Projekt1.exe] Error 1in den project einstellungen hab ich
bei parameter->linker folgendes stehen
-lmingw32 -lSDLmain -lSDL -lSDL_image -lSDL_ttf -lSDL_mixer
-
gcov scheint der Profiler zu sein. Deaktiviere die Profiling-Funktionen.
-
wie deaktivire ich das den