Problème de constructeur et d'héritage
Bonjour à vous,
Afin de continuer mon apprentissage du C++, j'ai chercher des bout de codes sur internet.
Après avoir compris certaine parties, j'ai du me renseigner pour comprendre certain point comme l'héritage.
J'ai donc essayé de recrée de mon côté les fonctions tout en découvrant.
Malheureusement, ça ne fonctionne, j'ai donc comparé aux sources original, et pourtant à l'identique mon code ne fonctionne pas.
Voici les codes en question :
Smash2D.h
Code:
1 2 3 4 5 6 7 8 9 10 11
|
#include "SDLGL_Application.h"
#include <SDL.h>
#include <string>
class Smash2D : public SDLGL_Application
{
public:
Smash2D(const WindowsParameters ¶meters);
}; |
Smash2D.cpp
Code:
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
| #include "Smash2D.h"
using namespace std;
Smash2D::Smash2D(const WindowsParameters ¶meters)
{
SDLGL_Application(parameters)
{
}
}
int main(int argc, char *argv[])
{
// Variables
SDL_Event event;
bool done = true;
// On crée une structure de parametres.
WindowsParameters parameters;
parameters.Title = "Test";
parameters.Width = 640;
parameters.Height = 480;
parameters.FullScreen = false;
// On crée la fenetre à l'aide des parametres.
Smash2D application(parameters);
return 0;
} |
SDLGL_Application.cpp
Code:
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
|
#include "SDLGL_Application.h"
// Parametres de la fenêtre par défault.
WindowsParameters::WindowsParameters()
{
Title = "Application SDL/OpenGL"; // Nom de la fenêtre.
Width = 640; // Largeur
Height = 480; // Hauteur
FullScreen = false; // Pleine ecran.
}
SDLGL_Application::SDLGL_Application(WindowsParameters parameters)
{
// Initialisation de la SDL.
SDL_Init(SDL_INIT_VIDEO);
// Debug.
#ifndef NDEBUG
freopen( "CON", "w", stdout );
freopen( "CON", "w", stderr );
#endif
// On enregistre le nom de la fenêtre.
SDL_WM_SetCaption(parameters.Title.c_str(), NULL);
// Les flags de la fenetres.
Uint32 flags = SDL_OPENGL;
// Si le pleine ecran est activer.
if(parameters.FullScreen)
{
// On ajoute le flags pleine ecran.
flags |= SDL_FULLSCREEN;
if (parameters.Width == 0 || parameters.Height == 0)
{
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
parameters.Width = videoInfo->current_w;
parameters.Height = videoInfo->current_h;
}
}
// On centre la fenetre (Dans le cas ou le pleine ecran est off)
SDL_putenv("SDL_VIDEO_WINDOW_POS=center");
SDL_SetVideoMode(parameters.Width, parameters.Height, 32, flags);
} |
SDLGL_Application.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| #ifndef H_SDLGL_APPLICATION
#define H_SDLGL_APPLICATION
#include <SDL.h>
#include <string>
struct WindowsParameters
{
WindowsParameters(); // Initialiser la structure.
std::string Title; // Stocke le titre de la fenêtre.
unsigned int Width; // Largeur de l'écran.
unsigned int Height; // Hauteur de l'écran.
bool FullScreen; // Gestion du pleine ecran.
};
class SDLGL_Application
{
public:
SDLGL_Application(WindowsParameters parameters);
};
#endif |
La classe Smash2D herite de la classe mere SDLG_Application.
Le problème, la classe fille Smash2D cherche son constructeur dans la classe mere SDLG_Application et me sort donc les erreurs suivantes :
Code:
1 2 3 4 5 6 7
|
In constructor `Smash2D::Smash2D(const WindowsParameters&)':
12: error: no matching function for call to `SDLGL_Application::SDLGL_Application()'
23: note: candidates are: SDLGL_Application::SDLGL_Application(const SDLGL_Application&)
25: note: SDLGL_Application::SDLGL_Application(WindowsParameters)
14: error: expected `;' before '{' token
:: === Build finished: 4 errors, 0 warnings === |
Merci à vous d'avoir pris le temps de m'avoir lu.
Hybrix.