编译器说成员未声明,显然不是。 (SDL)

Compiler says members are undeclared, they are clearly not. (SDL)

一切都很好,直到我决定重新开始我的项目并从头开始构建一个新框架。编译器告诉我在我的游戏 class 中声明的所有成员都未声明,即使它们就在那里。即使我在 class 中声明了一个简单的 int,它也不会在 Game.cpp 中看到它。我没有看到一些简单的东西。

Game.h

#ifndef __Game__
#define __Game__

#pragma once

#include "SDL.h"

class Game
{
public:
    Game();
    ~Game();

int Init(const char* title, int xPos, int yPos, int width, int height, int flags);

private:
SDL_Window* MainWindow;
SDL_Renderer* MainRenderer;
int CurrentFrame;
bool Running;
};

#endif

Game.cpp

#include "Game.h"
#include <iostream>
using namespace std;


Game::Game()
{

}


Game::~Game()
{

}

int Init(const char* title, int xPos, int yPos, int width, int height, int  flags)
{
if(SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
cout << "SDL init success\n";

 MainWindow = SDL_CreateWindow(title, xPos, yPos, width, height, flags);

if(MainWindow != 0) 
    {
    cout << "window creation success\n";
    MainRenderer = SDL_CreateRenderer(MainWindow, -1, 0);

        if(MainRenderer != 0) 
        {
        cout << "renderer creation success\n";
        SDL_SetRenderDrawColor(MainRenderer, 255,255,255,255);
        }
        else
        {
        cout << "renderer init fail\n";
        return false; 
        }
}
else
{
cout << "window init fail\n";
return false; 
}

}
else
{
cout << "SDL init fail\n";
return false; 
}
    cout << "init success\n";


return 0;


}

编译日志如下:

>------ Build started: Project: idcdc, Configuration: Debug Win32 ------
1>  Game.cpp
1>c:\users\cole\documents\visual studio      2010\projects\idcdc\idcdc\game.cpp(23): error C2065: 'MainWindow' : undeclared   identifier
1>c:\users\cole\documents\visual studio    2010\projects\idcdc\idcdc\game.cpp(25): error C2065: 'MainWindow' : undeclared  identifier
1>c:\users\cole\documents\visual studio   2010\projects\idcdc\idcdc\game.cpp(28): error C2065: 'MainRenderer' : undeclared  identifier
1>c:\users\cole\documents\visual studio  2010\projects\idcdc\idcdc\game.cpp(28): error C2065: 'MainWindow' : undeclared  identifier
1>c:\users\cole\documents\visual studio  2010\projects\idcdc\idcdc\game.cpp(30): error C2065: 'MainRenderer' : undeclared  identifier
1>c:\users\cole\documents\visual studio  2010\projects\idcdc\idcdc\game.cpp(33): error C2065: 'MainRenderer' : undeclared  identifier
1>  Generating Code...
1>  Compiling...
1>  Main.cpp
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

听起来应该有一个简单的答案,但很遗憾我不知道这里发生了什么,谢谢。

根据您对函数 Init 的定义,它不是 class Game 的成员。改为

int Game::Init(const char* title, int xPos, int yPos, int width, int height, int flags)