错误c ++ visual studio c2227' - > Init'必须指向class / struct / union / generic类型

时间:2017-11-06 15:47:41

标签: c++ visual-c++ error-code

我制作了一个简单的游戏窗口,可以加载2个精灵,但是我改变了加载方式,所以最好为每个Sprite创建另一个变量。 我收到以下错误:

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

这是我的代码:

MainGame.h

#pragma once
#include <SDL/SDL.h>
#include <GL/glew.h>
#include <vector>

#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 <Sprite*> _sprites;

GLSLProgram _colorProgram;

float _time;

};

MainGame.ccp

#include "MainGame.h"
#include <iostream>
#include <string>

#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_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    glClearColor(0.0f, 0.0f ,1.0f, 1.0f);

    initShaders();
}

void MainGame::initShaders() {
    _colorProgram.compileShaders("Shaders/colorShading.vert",     "Shaders/colorShading.frag");
    _colorProgram.addAttribute("vertexPosition");
    _colorProgram.addAttribute("vertexColor");
    _colorProgram.addAttribute("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 < _sprites.size(); i++) {
        _sprites[i]->draw();
    }

    glBindTexture(GL_TEXTURE_2D, 0);
    _colorProgram.unuse();

    //Swapping buffer Window
    SDL_GL_SwapWindow(_window);
}

如果您需要更多代码或其他类,请询问:)

这应该在屏幕上加载2个精灵,你可以从我的代码中看到,我很害怕这个,所以有些代码看起来像noob代码:(,请不要纠正我因为我知道事情我不是100%正确,但其他代码没有任何东西可以破坏我的 - &gt;初始精灵行,所以请帮助我,而不是如何让我的代码看起来没有看到noob代码:D

我已经非常感谢所有回复,希望我们能解决。

1 个答案:

答案 0 :(得分:0)

尝试

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

需要->back后的括号,它是一种方法。

相关问题