erreur c ++ visual studio c2227 À gauche de ‘-> Init’ doit pointer vers le type class / struct / union / generic

J’ai créé une fenêtre de jeu simple qui charge 2 sprites, mais j’ai changé ma méthode de chargement. Il serait donc préférable de créer pour chaque Sprite une autre variable. Je reçois l’erreur suivante:

c2227 left of '->Init' must point to class/struct/union/generic type c2227 left of '->Init' must point to class/struct/union/generic type 

Et voici mon code:

MainGame.h

 #pragma once #include  #include  #include  #include "GLTexture.h" #include "GLSLProgram.h" #include "Sprite.h" enum class GameState {PLAY, EXIT}; class MainGame { public: MainGame(); ~MainGame(); void run(); void drawGame(); private: void initSystems(); void initShaders(); void gameLoop(); void processInput(); SDL_Window* _window; int _ScreenWidth; int _ScreenHeight; GameState _gameState; std::vector  _sprites; GLSLProgram _colorProgram; float _time; }; 

MainGame.ccp

 #include "MainGame.h" #include  #include  #include "Errors.h" MainGame::MainGame() : _ScreenWidth(1024), _ScreenHeight(768), _window(nullptr), _gameState(GameState::PLAY) { } //Destructer MainGame::~MainGame() { } void MainGame::run() { initSystems(); _sprites.push_back(new Sprite()); _sprites.back->Init(0.0f, -1.0f, 1.0f, 1.0f, "Textures/jimmyJump_pack/PNG/CharacterRight_Standing.png"); _sprites.push_back(new Sprite()); _sprites.back->Init(-1.0f, -1.0f, 1.0f, 1.0f, "Textures/jimmyJump_pack/PNG/CharacterRight_Standing.png"); //_playerTexture = ImageLoader::loadPNG("Textures/jimmyJump_pack/PNG/CharacterRight_Standing.png"); gameLoop(); } void MainGame::initSystems() { //Init SDL SDL_Init(SDL_INIT_EVERYTHING); //Set up Window _window = SDL_CreateWindow("Iskallium Engine >> Game Title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _ScreenWidth, _ScreenHeight, SDL_WINDOW_OPENGL); if (_window == nullptr) { fatalError("Iskallium Engine could not be opened"); } //Set up OpenGL SDL_GLContext glContext = SDL_GL_CreateContext(_window); if (glContext == nullptr) { fatalError("Iskallium Engine could not start Model-Loader"); } //Set up glew glewExperimental = true; GLenum error = glewInit(); if (error != GLEW_OK) { fatalError("Could not initialize glew!"); } SDL_GL_SetAtsortingbute(SDL_GL_DOUBLEBUFFER, 1); glClearColor(0.0f, 0.0f ,1.0f, 1.0f); initShaders(); } void MainGame::initShaders() { _colorProgram.comstackShaders("Shaders/colorShading.vert", "Shaders/colorShading.frag"); _colorProgram.addAtsortingbute("vertexPosition"); _colorProgram.addAtsortingbute("vertexColor"); _colorProgram.addAtsortingbute("vertexUV"); _colorProgram.linkSchaders(); } void MainGame::gameLoop() { while (_gameState != GameState::EXIT) { processInput(); drawGame(); } } void MainGame::processInput() { SDL_Event evnt; while (SDL_PollEvent(&evnt)) { switch (evnt.type) { case SDL_QUIT: _gameState = GameState::EXIT; break; case SDL_MOUSEMOTION: //std::cout << evnt.motion.x << " " << evnt.motion.y << std::endl; break; } } } void MainGame::drawGame() { glClearDepth(1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); _colorProgram.use(); glActiveTexture(GL_TEXTURE0); GLint textureLocation = _colorProgram.getUniformLocation("mySampler"); glUniform1i(textureLocation, 0); //Draw sprite for (int i = 0; i draw(); } glBindTexture(GL_TEXTURE_2D, 0); _colorProgram.unuse(); //Swapping buffer Window SDL_GL_SwapWindow(_window); } 

si vous avez besoin de plus de code ou d’autres classes, demandez simplement 🙂

Cela devrait charger 2 sprites de sur l’écran comme vous pouvez le voir dans mon code, je suis terriblement nouveau dans ce domaine, alors certains codes ressembleront à du code noob :(, s’il vous plaît, ne me corrigez pas car je sais des choses que je ne connais pas 100% correctement mais rien de l’autre code ne devrait corrompre ma ligne -> Init Sprite, alors aidez-moi, s’il vous plaît, et comment faire en sorte que mon code ne ressemble pas à noob code: D

Déjà un énorme merci pour toutes les réponses que je vais obtenir, espérons que nous pourrons le résoudre.

Essayer avec

_sprites.back()->Init(0.0f, -1.0f, 1.0f, 1.0f, "Textures/jimmyJump_pack/PNG/CharacterRight_Standing.png");

Les parenthèses après ->back sont nécessaires, c’est une méthode.