Partage
  • Partager sur Facebook
  • Partager sur Twitter

Problème de passage de pointeur...

Sujet résolu
    8 mai 2008 à 18:07:54

    Salut amis zeros,
    Bon voilà j'ai un petit problème, j'ai créé une class menu qui est ainsi:
    class menu{
        private:
            SDL_Surface *fond;
            SDL_Rect positionFond;
    
        public:
            menu()
            {
            fond = IMG_Load("fond.jpg");
            positionFond.x = 0;
            positionFond.y = 0;
            }
            void afficher(SDL_Surface *ecran)
            {
            SDL_BlitSurface(fond, 0, ecran, &positionFond);
            }
    };
    


    et mon corps de programme ressemble à ça
    int main ( int argc, char** argv )
    {
        // initialize SDL video
        SDL_Init( SDL_INIT_VIDEO );
    
        // on crée la fenetre
        SDL_Surface* screen = SDL_SetVideoMode(800, 600, 16,
                                               SDL_HWSURFACE|SDL_DOUBLEBUF);
    
    
        menu menuPrincipal;
    
        // main loop
        bool arret = false;
        while (!arret)
        {
            // message processing loop
            SDL_Event event;
            while (SDL_PollEvent(&event))
            {
                // check for messages
                switch (event.type)
                {
                    // exit if the window is closed
                case SDL_QUIT:
                    arret = true;
                    break;
    
                    // check for keypresses
                case SDL_KEYDOWN:
                    {
                        // exit if ESCAPE is pressed
                        if (event.key.keysym.sym == SDLK_ESCAPE)
                            arret = true;
                        break;
                    }
                } // end switch
            } // end of message processing
    
    
    
            // on efface l'ecran
            SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
    
           menuPrincipal.afficher(&screen);
    
            // DRAWING ENDS HERE
    
            // finally, update the screen 
            SDL_Flip(screen);
        } // end main loop
    
        // free loaded bitmap
        SDL_FreeSurface(fond);
    
        return 0;
    }
    


    Rien de très compliqué... je sais que le code du menu n'est pas pensé de façon optimale, mais là c'est juste pour m'entrainer au c++, bon alors voila le problème est au niveau de:
    menuPrincipal.afficher(&screen);
    

    et donc aussi
    void afficher(SDL_Surface *ecran)
    


    car le compilateur me reponds ceci:
    C:\Users\tiboo\Documents\project2D\vcb\main.cpp||In function `int SDL_main(int, char**)':|
    C:\Users\tiboo\Documents\project2D\vcb\main.cpp|76|error: no matching function for call to `menu::afficher(SDL_Surface&)'|
    C:\Users\tiboo\Documents\project2D\vcb\main.cpp|27|note: candidates are: void menu::afficher(SDL_Surface*)|
    C:\Users\tiboo\Documents\project2D\vcb\main.cpp|85|error: `fond' was not declared in this scope|
    C:\Users\tiboo\Documents\project2D\vcb\main.cpp|85|warning: unused variable 'fond'|
    ||=== Build finished: 2 errors, 1 warnings ===|


    merci d'avance ;)
    • Partager sur Facebook
    • Partager sur Twitter
      8 mai 2008 à 19:23:50

      ne libere pas "fond" dans le main() mais dans le destructeur de ta classe (=> RAII)

      tu ne dois pas envoyer l'addresse de ton pointeur à afficher()
      • Partager sur Facebook
      • Partager sur Twitter
        8 mai 2008 à 20:05:13

        ah oui c'est bon je l'ai appelé en faisant

        menuPrincipal.afficher(screen); et ça marche... merci encore ;)
        • Partager sur Facebook
        • Partager sur Twitter

        Problème de passage de pointeur...

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown