Partage
  • Partager sur Facebook
  • Partager sur Twitter

Passer un attribut de type "ostringstream" à un fonction ?

Sujet résolu
    4 août 2007 à 23:20:07

    Bonjour amis Zéros :)

    Je souhaiterai simplement savoir comment proceder pour passer l'attribut : "ostringstream" en argument de fonction (ou methode plus exactement :p ).
    Car j'ai procédé comme cela (la variable qui m'interresse est la variable phrase):

    Dans le main.cpp :
    #include <sstream>
    #include <iostream>
    #include <string>
    #include <time.h>

    #include <SDL/SDL.h>
    #include <SDL/SDL_image.h>
    #include <SDL/SDL_ttf.h>

    #include "keyboard.h"


    void pause(bool *continuer, SDL_Event *event);

    using namespace std;

    int main(int argc, char *argv[])
    {
            //Initialisation de la SDL
            SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
            TTF_Init();
     
            SDL_WM_SetCaption("Test", NULL);
     
            //Initialisation des image
            SDL_Surface *ecran = ecran = SDL_SetVideoMode(480, 272, 32, SDL_HWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF);
            SDL_Surface *background = IMG_Load("gfx/background.png");
            SDL_Surface *texte = NULL;
     
            //Initialisation des Positions des images
            SDL_Rect background_position;
            background_position.x = 0;
            background_position.y = 0;

            SDL_Rect texte_position;
            texte_position.x = 10;
            texte_position.y = 15;

            SDL_Color couleurBlanche = {255, 255, 255};

            SDL_Event event;
            SDL_EnableKeyRepeat(10, 10);

            bool continuer = true;
            Osk poison;

            ostringstream phrase;
     

            while(continuer == true)
            {
     
            SDL_WaitEvent(&event);

            SDL_BlitSurface(background, NULL, ecran, &background_position);

            poison.Init(&event, ecran, texte, phrase, &texte_position, &couleurBlanche);

            SDL_Flip(ecran);
            pause(&continuer, &event);
            }

    SDL_FreeSurface(ecran);
    SDL_FreeSurface(background);
    SDL_Quit();
    TTF_Quit();
    return EXIT_SUCCESS;
    }


    void pause(bool *continuer, SDL_Event *event)
    {
            switch(event->type)
            {
                case SDL_QUIT:
                    (*continuer) = 0;
            }
    }



    Mon keyboard .h :

    #ifndef DEF_KEYBOARD
    #define DEF_KEYBOARD

    #include <sstream>
    #include <string>

    class Osk
    {
            public:

            Osk();
            void Init(SDL_Event *event, SDL_Surface *ecran, std::ostringstream *phrase, SDL_Surface *texte, SDL_Rect *texte_position, SDL_Color *couleurBlanche);

            private:

            SDL_Surface *m_osk_min;
            SDL_Surface *m_osk_maj;
            SDL_Surface *m_osk_img;
            SDL_Surface *m_osk_selector;
           
            std::string m_sentence;
            std::string m_alphabet;
            std::string m_alphabet_min;
            std::string m_alphabet_maj;
            char m_selector;
            char m_choix_letter;
            char m_appuisCROSS;
            char m_appuisRIGHT;
            char m_appuisLEFT;
            char m_appuisDOWN;
            char m_appuisUP;
            char m_minuscule;

            TTF_Font *m_Font;

    };

    #endif
     


    Et mon keyboard.cpp :

    #include <sstream>
    #include <iostream>
    #include <string>

    #include <SDL/SDL.h>
    #include <SDL/SDL_image.h>
    #include <SDL/SDL_ttf.h>

    #include "keyboard.h"

    using namespace std;

    Osk::Osk()
    {
            m_osk_min = IMG_Load("gfx/keyboard/keyboard_min.png");
            m_osk_maj = IMG_Load("gfx/keyboard/keyboard_maj.png");
            m_osk_img = IMG_Load("gfx/keyboard/keyboard_min.png");
            m_osk_selector = IMG_Load("gfx/keyboard/selector_keyboard.png");
           
            m_sentence = "x";
            m_alphabet = "012345678abcdefgh9ijklmnop.qrstuvwx_yz -";
            m_alphabet_min = "012345678abcdefgh9ijklmnop.qrstuvwx_yz -";
            m_alphabet_maj = "012345678ABCDEFGH9IJKLMNOP.QRSTUVWX_YZ -";
            m_selector = 0;
            m_choix_letter = 0;
            m_appuisCROSS = 0;
            m_appuisRIGHT = 0;
            m_appuisLEFT = 0;
            m_appuisDOWN = 0;
            m_appuisUP = 0;
            m_minuscule = 1;

            m_Font = TTF_OpenFont("./Vera.ttf", 20);

    }

    void Osk::Init(SDL_Event *event, SDL_Surface *ecran, ostringstream *phrase, SDL_Surface *texte, SDL_Rect *texte_position, SDL_Color *couleurBlanche)
    {

    //Pour l'instant il n'y a rien, mais c'est juste pour tester si le passage de ostringstream *phrase fonctionne

    }


    Et lorsque je compile, j'ai une petite erreur :

    poison@poison-desktop:~/Programme/Programmation/Linux/PROJETS/Test$ g++ -o test -lSDL -lSDLmain -lSDL_image -lSDL_ttf -lstdc++ main.cpp keyboard.cpp
    main.cpp: In function ‘int main(int, char**)’:
    main.cpp:57: error: no matching function for call to ‘Osk::Init(SDL_Event*, SDL_Surface*&, SDL_Surface*&, std::ostringstream&, SDL_Rect*, SDL_Color*)’
    keyboard.h:12: note: candidates are: void Osk::Init(SDL_Event*, SDL_Surface*, std::ostringstream*, SDL_Surface*, SDL_Rect*, SDL_Color*)


    Si quelqu'un pouvais m'indiquer la marche a suivre sa serait sympatique, merci d'avance &#59;&#41;
    • Partager sur Facebook
    • Partager sur Twitter
      5 août 2007 à 1:45:58

      Une simple référence sur un std::ostream suffira amplement
      • Partager sur Facebook
      • Partager sur Twitter
      C++: Blog|FAQ C++ dvpz|FAQ fclc++|FAQ Comeau|FAQ C++lite|FAQ BS| Bons livres sur le C++| PS: Je ne réponds pas aux questions techniques par MP.
        5 août 2007 à 9:09:36

        Merci pour ton aide, malheureusement, je viens d'essayer et sa ne fonctionne pas :( , voici comment j'ai procédé :

        Dans mon main.cpp :

                //Plein de code...

                //Je déclare la variable
                ostringstream phrase;

                //Boucle while

                //Appel de la fonction
                poison.Init(&event, ecran, texte, phrase, &texte_position, &couleurBlanche);


        Dans mon keyboard.h :

        class Osk
        {
                public:

                Osk();
                void Init(SDL_Event *event, SDL_Surface *ecran, std::ostringstream &Refphrase, SDL_Surface *texte, SDL_Rect *texte_position, SDL_Color *couleurBlanche);

                private:
             
                //Déclaration des variables
        }


        Et mon keyboard.cpp :

        Osk::Osk()
        {
                //Chargement des variables

        }

        void Osk::Init(SDL_Event *event, SDL_Surface *ecran, ostringstream &Refphrase, SDL_Surface *texte, SDL_Rect *texte_position, SDL_Color *couleurBlanche)
        {



        }


        L'erreur est toujours la meme :

        main.cpp: In function ‘int main(int, char**)’:
        main.cpp:57: error: no matching function for call to ‘Osk::Init(SDL_Event*, SDL_Surface*&, SDL_Surface*&, std::ostringstream&, SDL_Rect*, SDL_Color*)’
        keyboard.h:12: note: candidates are: void Osk::Init(SDL_Event*, SDL_Surface*, std::ostringstream&, SDL_Surface*, SDL_Rect*, SDL_Color*)


        Merci d'avance pour votre aide
        • Partager sur Facebook
        • Partager sur Twitter
          5 août 2007 à 9:26:59

          Regarde bien les deux signatures. L'erreur n'est pas là où tu penses.

          PS: Souviens-toi du jeu des 7 erreurs (différences à vrai dire), sauf que là il n'y en a qu'une.
          • Partager sur Facebook
          • Partager sur Twitter
          C++: Blog|FAQ C++ dvpz|FAQ fclc++|FAQ Comeau|FAQ C++lite|FAQ BS| Bons livres sur le C++| PS: Je ne réponds pas aux questions techniques par MP.
            5 août 2007 à 9:51:14

            La différence que je vois entre les deux signatures, est que dans le keyboard.cpp j'ai :

            void Osk::Init(SDL_Event *event, SDL_Surface *ecran, ostringstream &Refphrase, SDL_Surface *texte, SDL_Rect *texte_position, SDL_Color *couleurBlanche)


            Donc ostringstream &Refphrase, tandis que dans le keyboard.h j'ai std::ostringstream &Refphrase:

            void Init(SDL_Event *event, SDL_Surface *ecran, std::ostringstream &Refphrase, SDL_Surface *texte, SDL_Rect *texte_position, SDL_Color *couleurBlanche);


            Mais je ne pense pas que l'erreur vienne d'ici puisque dans mon keyboard.cpp j'ai bien mi :

            using namespace std;

            Voila mon keyboard.cpp complet :

            #include <sstream>
            #include <iostream>
            #include <string>

            #include <SDL/SDL.h>
            #include <SDL/SDL_image.h>
            #include <SDL/SDL_ttf.h>

            #include "keyboard.h"

            using namespace std;

            Osk::Osk()
            {
                    m_osk_min = IMG_Load("gfx/keyboard/keyboard_min.png");
                    m_osk_maj = IMG_Load("gfx/keyboard/keyboard_maj.png");
                    m_osk_img = IMG_Load("gfx/keyboard/keyboard_min.png");
                    m_osk_selector = IMG_Load("gfx/keyboard/selector_keyboard.png");
                   
                    m_sentence = "x";
                    m_alphabet = "012345678abcdefgh9ijklmnop.qrstuvwx_yz -";
                    m_alphabet_min = "012345678abcdefgh9ijklmnop.qrstuvwx_yz -";
                    m_alphabet_maj = "012345678ABCDEFGH9IJKLMNOP.QRSTUVWX_YZ -";
                    m_selector = 0;
                    m_choix_letter = 0;
                    m_appuisCROSS = 0;
                    m_appuisRIGHT = 0;
                    m_appuisLEFT = 0;
                    m_appuisDOWN = 0;
                    m_appuisUP = 0;
                    m_minuscule = 1;

                    m_Font = TTF_OpenFont("./Vera.ttf", 20);

            }

            void Osk::Init(SDL_Event *event, SDL_Surface *ecran, ostringstream &Refphrase, SDL_Surface *texte, SDL_Rect *texte_position, SDL_Color *couleurBlanche)
            {



            }


            Suis-je myope ? :-°
            • Partager sur Facebook
            • Partager sur Twitter
              5 août 2007 à 10:17:44

              oui. Continue à chercher
              Indice: juste après la prochaine virgule.
              • Partager sur Facebook
              • Partager sur Twitter
              C++: Blog|FAQ C++ dvpz|FAQ fclc++|FAQ Comeau|FAQ C++lite|FAQ BS| Bons livres sur le C++| PS: Je ne réponds pas aux questions techniques par MP.
                5 août 2007 à 10:26:55

                Honte à moi &#58;&#108;&#111;&#108;&#58; en fait le probleme se trouve dans mon main.cpp :

                J'avais mis :

                poison.Init(&event, ecran, texte, phrase, &texte_position, &couleurBlanche);


                Alors qu'il faut que je mette la variable phrase avant la variable texte :

                poison.Init(&event, ecran, phrase, texte, &texte_position, &couleurBlanche);


                Merci beaucoup pour ton aide, sans toi j'aurai continué a chercher au mauvais endroit pendant je ne sais combien de temps &#58;&#68;
                • Partager sur Facebook
                • Partager sur Twitter

                Passer un attribut de type "ostringstream" à un fonction ?

                × 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