Problem mit delete()



  • Meine Klasse hat folgenden Aufbau:

    class TUIManager
    { //Manager for the OpenGL-SDL-userinterface
      private: 
    
        ...
    
        vector<TTF_Font*> FontList;		//stores all fonts which are used in the GUI
        vector<string*> FontNameTable;	//stores pointers to the names of the fonts. The i-th string is the name of the font with ID=i.
    
        ...
    
      public:
        // Constructor
        TUIManager();
    
        // Destructor
        ~TUIManager();
    
        //----------------------Methodes------------------------------------
    
        ...
    
        // Returns true if the font was deleted, else false.
        bool deleteFont(int fontID);
    };
    
    // Returns true if the font was deleted, else false.
    bool TUIManager::deleteFont(int fontID)
    {
    	if ( (fontID >= 0)&&( (unsigned int)fontID < FontList.size() ) )
    	{
    		if (FontList[fontID] == NULL) return true;
    
    		TTF_CloseFont(FontList[fontID]);
    		delete(FontList[fontID]);
    		FontList[fontID] = NULL;
    		delete(FontNameTable[fontID]);
    		FontNameTable[fontID] = NULL;
    		return true;
    	}
    
    	return false;
    }
    

    Beim aufruf der Methode deleteFont() bekomme ich bei

    delete(FontList[fontID]);
    

    folgenden Compiler-Fehler:

    ../src/TUIManager.cpp: In member function `bool TUIManager::deleteFont(int)':
    ../src/TUIManager.cpp:546: warning: possible problem detected in invocation of delete operator:
    ../src/TUIManager.cpp:546: warning: invalid use of undefined type `struct _TTF_Font'
    C:/Programmieren/Imported_Libs/SDL_ttf-2.0.7/include/SDL_ttf.h:80: warning: forward declaration of `struct _TTF_Font'
    ../src/TUIManager.cpp:546: note: neither the destructor nor the class-specific operator delete will be called, 
      even if they are declared when the class is defined.
    

    Im header ist die datei SDL_TTF includiert, welche die Klasse TTF_Font bereitstellt.

    Was mach ich falsch?



  • Fehlen auch noch Infos, oder wieso könnt ihr mir nicht weiterhelfen?



  • TTF_CloseFont() gibt den Speicher frei und invalidiert dadurch den Zeiger. Da gibt es nichts mit delete zu loeschen, zumal Du es auch nicht mit new erzeugst.

    Siehe auch: http://jcatki.no-ip.org/SDL_ttf/SDL_ttf.html#SEC18



  • Danke. Da hätte ich selber drauf kommen müssen.

    Es sind immer die Einfachsten Dinge die einen am längsten aufhalten.



  • Keine Ursache.


Anmelden zum Antworten