IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Classe héritée ne trouve pas la méthode de ma classe mère.


Sujet :

C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Invité
    Invité(e)
    Par défaut Classe héritée ne trouve pas la méthode de ma classe mère.
    Salut!
    J'ai une classe dans un namespace SDLWindow :
    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
     
    #include "../../../include/odfaeg/Graphics/sdlWindow.hpp"
    namespace odfaeg {
        namespace window {
            SDLWindow::SDLWindow(unsigned int width, unsigned int height, std::string title) {
                create(width, height,title);
            }
            void SDLWindow::create(unsigned int width, unsigned int height, std::string title) {
                window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED,
                                          SDL_WINDOWPOS_UNDEFINED,
                                          width,
                                          height,
                                          SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
                this->width = width;
                this->height = height;
            }
            void SDLWindow::initSDL() {
                if (SDL_Init(SDL_INIT_VIDEO) != 0 )
                {
                    fprintf(stdout,"Échec de l'initialisation de la SDL (%s)\n",SDL_GetError());
                    return -1;
                }
            }
            void SDLWindow::onCreate() {
     
            }
            void SDLWindow::onResize() {
     
            }
            void SDLWindow::setPosition(unsigned int x, unsigned int y) {
                SDL_SetWindowPosition(window, x, y);
            }
            bool SDLWindow::pollEvent(SDL_Event event) {
            }
            bool SDLWindow::isOpen() {
                return window != nullptr;
            }
            void SDLWindow::close() {
                SDL_DestroyWindow(window);
                window = nullptr;
            }
            void SDLWindow::display() {
                SDL_GL_SwapWindow(window);
            }
            SDL_Window* SDLWindow::getWindow() {
                return window;
            }
            SDLWindow::~SDLWindow() {
                SDL_DestroyWindow(window);
            }
        }
    }

    Et une autre classe dans un autre namespace qui hérite de SDLWindow :
    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
     
    #include "../../../include/odfaeg/Graphics/sdlRenderWindow.hpp"
    #include "glCheck.h"
    namespace odfaeg {
        namespace graphic {
            using namespace sf;
            SDLRenderWindow::SDLRenderWindow(unsigned int width, unsigned int height, const std::string& title, const sf::ContextSettings& settings)
            {
                this->settings = settings;
                activated = false;
                create(width, height, title);
            }
            bool SDLRenderWindow::activate(bool active) {
                if (active && !activated) {
                    if(SDL_GL_MakeCurrent(window::SDLWindow::getWindow(), context)) {
                        return false;
                    } else {
                        activated = true;
                        return true;
                    }
                } else if (!active && activated) {
                    if(SDL_GL_MakeCurrent(window::SDLWindow::getWindow(), nullptr)) {
                        return false;
                    } else {
                        activated = false;
                        return true;
                    }
                }
                return true;
            }
            bool SDLRenderWindow::isActive() {
                return activated;
            }
            bool SDLRenderWindow::isUsingDepthTest() const {
                return useDepthTest;
            }
            void SDLRenderWindow::onCreate() {
                SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
                SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, settings.majorVersion);
                SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, settings.minorVersion);
                SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, settings.stencilBits);
                SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, settings.depthBits);
                SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (settings.antialiasingLevel > 0) ? 1 : 0);
                SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, settings.antialiasingLevel);
                context = SDL_GL_CreateContext(window);
                priv::ensureGlewInit();
                /*glewExperimental = GL_TRUE;
                GLenum status = glewInit();
                if (status == GLEW_OK)
                {
                    std::cout<<"Glew initialized!"<<std::endl;
                }
                else
                {
                    err() << "Failed to initialize GLEW, " << glewGetErrorString(status) << std::endl;
                }*/
                // Just initialize the render target part
                RenderTarget::initialize();
            }
            SDLRenderWindow::~SDLRenderWindow() {
                SDL_GL_DeleteContext(context);
            }
        }
    }

    Le problème c'est que le compilateur me dit qu'il ne trouve pas la méthode getWindow() de la classe mère :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    /home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Graphics/sdlRenderWindow.cpp|14|error: ‘getWindow’ is not a member of ‘odfaeg::window::SDLWindow’|
    Est ce que la classe mère doit être dans le même namespace que la classe fille ?
    Dernière modification par Invité ; 04/01/2019 à 15h19.

  2. #2
    Invité
    Invité(e)
    Par défaut
    Je les ai mit dans le même namespace mais même problème.

  3. #3
    Invité
    Invité(e)
    Par défaut
    Ho et puis merde j'ai pas le temps.
    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #ifndef SDL_WINDOW
    #define SDL_WINDOW
    #include <SDL2/SDL.h>
    #include <string>
    namespace odfaeg {
        namespace window {
            class SDLWindow {
                public :
                SDLWindow();
                SDLWindow(unsigned int width, unsigned int height, std::string title);
                void create(unsigned int width, unsigned int height, std::string title);
                void setPosition(unsigned int x, unsigned int y);
                virtual void onCreate();
                bool isOpen();
                void close();
                bool pollEvent(SDL_Event &event);
                void setVisible (bool visible);
                virtual ~SDLWindow();
                public :
                void initialize();
                SDL_Window* window;
            };
        }
    }
    #endif // SDL_WINDOW
    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    void SDLRenderWindow::onCreate() {
                SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
                SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, settings.majorVersion);
                SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, settings.minorVersion);
                SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, settings.stencilBits);
                SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, settings.depthBits);
                SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (settings.antialiasingLevel > 0) ? 1 : 0);
                SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, settings.antialiasingLevel);
                context = SDL_GL_CreateContext(window);
                priv::ensureGlewInit();
                /*glewExperimental = GL_TRUE;
                GLenum status = glewInit();
                if (status == GLEW_OK)
                {
                    std::cout<<"Glew initialized!"<<std::endl;
                }
                else
                {
                    err() << "Failed to initialize GLEW, " << glewGetErrorString(status) << std::endl;
                }*/
                // Just initialize the render target part
                RenderTarget::initialize();
            }

  4. #4
    Membre confirmé
    Homme Profil pro
    Technicien Help Desk
    Inscrit en
    Janvier 2019
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Russie

    Informations professionnelles :
    Activité : Technicien Help Desk
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2019
    Messages : 25
    Par défaut
    Bonsoir Laurent7601,
    Peut-être je me trompe, mais il semble que la classe héritée doit connaître la méthode de la classe mère sans "scope resolution":

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SDL_GL_MakeCurrent(SDLWindow::getWindow(), context)
    Il me semble que c'est l'appel d'une méthode "static"
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    window::SDLWindow::getWindow()
    Excusez-moi pour mon français qui n'est pas bien.

  5. #5
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 522
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 522
    Par défaut
    Où est déclaré (donc dans le .h) la méthode "getWindow" de la classe "SDLWindow" ?

  6. #6
    Membre très actif
    Avatar de smarlytomtom
    Homme Profil pro
    Développeur de jeux vidéo
    Inscrit en
    Novembre 2014
    Messages
    139
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Territoire de Belfort (Franche Comté)

    Informations professionnelles :
    Activité : Développeur de jeux vidéo
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2014
    Messages : 139
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par bacelar Voir le message
    Où est déclaré (donc dans le .h) la méthode "getWindow" de la classe "SDLWindow" ?
    Comme le dit Bacelar, aucune déclaration du prototype de la méthode getWindow dans ton header... En ce qui concerne l'appel si elle n'est pas surchargé dans la classe fille alors tu dois l’appeler sans préciser le nom de la classe mère :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    getWindow() // Pas virtuel dans la classe mère donc pas override dans la classe fille, on l'appelle donc comme ça.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 20/06/2012, 09h27
  2. Je ne trouve pas les méthodes coté client
    Par Invité dans le forum Services Web
    Réponses: 1
    Dernier message: 24/02/2011, 18h15
  3. (macosX,eclipse 3.4) classe JPA non trouvée pas un EJB
    Par olivier57b dans le forum Glassfish et Payara
    Réponses: 16
    Dernier message: 17/01/2009, 22h32
  4. Réponses: 2
    Dernier message: 31/07/2007, 14h12
  5. [JNI] Java ne trouve pas mes méthodes natives
    Par carotte31 dans le forum Entrée/Sortie
    Réponses: 5
    Dernier message: 14/06/2006, 21h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo